[Pkg-bazaar-commits] ./bzr/unstable r364: - Create lockfiles in old branches that don't have one

Martin Pool mbp at sourcefrog.net
Fri Apr 10 07:43:43 UTC 2009


------------------------------------------------------------
revno: 364
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Thu 2005-05-05 16:43:04 +1000
message:
  - Create lockfiles in old branches that don't have one
modified:
  bzrlib/branch.py
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2005-05-05 06:09:54 +0000
+++ b/bzrlib/branch.py	2005-05-05 06:43:04 +0000
@@ -123,7 +123,7 @@
     def lock(self, mode='w'):
         """Lock the on-disk branch, excluding other processes."""
         try:
-            import fcntl
+            import fcntl, errno
 
             if mode == 'w':
                 lm = fcntl.LOCK_EX
@@ -134,11 +134,16 @@
             else:
                 raise BzrError("invalid locking mode %r" % mode)
 
-            # XXX: Old branches might not have the lock file, and
-            # won't get one until someone does a write-mode command on
-            # them or creates it by hand.
-
-            lockfile = os.open(self.controlfilename('branch-lock'), om)
+            try:
+                lockfile = os.open(self.controlfilename('branch-lock'), om)
+            except OSError, e:
+                if e.errno == errno.ENOENT:
+                    # might not exist on branches from <0.0.4
+                    self.controlfile('branch-lock', 'w').close()
+                    lockfile = os.open(self.controlfilename('branch-lock'), om)
+                else:
+                    raise e
+            
             fcntl.lockf(lockfile, lm)
             def unlock():
                 fcntl.lockf(lockfile, fcntl.LOCK_UN)



More information about the Pkg-bazaar-commits mailing list