~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2005-05-05 06:43:04 UTC
  • Revision ID: mbp@sourcefrog.net-20050505064304-b58b2080665f44cf
- Create lockfiles in old branches that don't have one

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
    def lock(self, mode='w'):
124
124
        """Lock the on-disk branch, excluding other processes."""
125
125
        try:
126
 
            import fcntl
 
126
            import fcntl, errno
127
127
 
128
128
            if mode == 'w':
129
129
                lm = fcntl.LOCK_EX
134
134
            else:
135
135
                raise BzrError("invalid locking mode %r" % mode)
136
136
 
137
 
            # XXX: Old branches might not have the lock file, and
138
 
            # won't get one until someone does a write-mode command on
139
 
            # them or creates it by hand.
140
 
 
141
 
            lockfile = os.open(self.controlfilename('branch-lock'), om)
 
137
            try:
 
138
                lockfile = os.open(self.controlfilename('branch-lock'), om)
 
139
            except OSError, e:
 
140
                if e.errno == errno.ENOENT:
 
141
                    # might not exist on branches from <0.0.4
 
142
                    self.controlfile('branch-lock', 'w').close()
 
143
                    lockfile = os.open(self.controlfilename('branch-lock'), om)
 
144
                else:
 
145
                    raise e
 
146
            
142
147
            fcntl.lockf(lockfile, lm)
143
148
            def unlock():
144
149
                fcntl.lockf(lockfile, fcntl.LOCK_UN)