win32 file locking

John A Meinel john at arbash-meinel.com
Wed May 25 07:43:43 BST 2005


How about this patch:
*** modified file 'bzrlib/atomicfile.py'
--- bzrlib/atomicfile.py
+++ bzrlib/atomicfile.py
@@ -47,7 +47,8 @@

     def __del__(self):
         """Abort if the file has not already been closed."""
-        self.close()
+        if not self.closed:
+            raise RuntimeError('AtomicFile must have
commit()/abort()/close() called before it expires.')

     def commit(self):
         """Close the file and move to final name."""

This way AtomicFile will throw an exception if it is not used correctly.

The problem for Branch() is that I don't think anyone is going to go
around and call "unlock()" when they are done with it, meaning that all
branches are locked for the lifetime of bzrlib. Since bzrlib is meant to
be a library, potentially used by a GUI, this could be a long time.

The problem is that Branch() is commonly used as a temporary object. For
instance the 'bzr revno' command is done like:

print Branch('.').revno()

How do you unlock a branch if you never have an object to call
'unlock()' on?

Maybe the above is poor form, and you should always create a real object
for Branch(). But I think the above idiom is obvious, you only want the
Branch to exist long enough to return the revno(), so it should unlock
when it is done.

Speaking of this code, shouldn't this at least be

print Branch('.', lock_mode='r').revno()

John
=:->

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20050525/32d0f9eb/attachment.pgp 


More information about the bazaar mailing list