Opened 16 years ago

Closed 16 years ago

#64 closed defect (fixed)

bug in Tub.registerReference when name provided

Reported by: bgranger Owned by:
Priority: major Milestone: 0.2.8
Component: unknown Version: 0.2.5
Keywords: Tub Cc:

Description (last modified by Brian Warner)

The following call doesn't work:

mytub.registerReference(fooo, 'fooname', furlFile='foo.furl')

If foo.furl already exists. This is because in registerReference, there is code:

       oldfurl = None
       if furlFile:
           try:
               oldfurl = open(furlFile, "r").read().strip()
           except EnvironmentError:
               pass
       if oldfurl:
           if name is None:
               sr = SturdyRef(oldfurl)
               name = sr.name
           if self.tubID != sr.tubID:      # problem occurs here!!!
               raise WrongTubIdError("I cannot keep using the old FURL (%s)"
                                     " because it does not have the same"
                                     " TubID as I do (%s)" %
                                     (oldfurl, self.tubID))

If there is an existing furlFile (oldfurl == True), but there is a name set, no local object called sr gets created and an exception is raised.

The following seems to fix the problem:

        oldfurl = None
        if furlFile:
            try:
                oldfurl = open(furlFile, "r").read().strip()
            except EnvironmentError:
                pass
        if oldfurl:
            sr = SturdyRef(oldfurl)
            if name is None:
                name = sr.name
            if self.tubID != sr.tubID:
                raise WrongTubIdError("I cannot keep using the old FURL (%s)"
                                      " because it does not have the same"
                                      " TubID as I do (%s)" %
                                      (oldfurl, self.tubID))

By moving the creation of sr outside the if name is None test, the sr object gets created no matter what so it is available in the subsequent if self.tubID != sr.tubID test.

Change History (3)

comment:1 Changed 16 years ago by Brian Warner

Description: modified (diff)

fix code formatting

comment:2 Changed 16 years ago by Brian Warner

Milestone: undecided0.2.8

comment:3 Changed 16 years ago by Brian Warner

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.