]> arthur.barton.de Git - bup.git/commitdiff
bloom-cmd.py: close open file object for tfname before attempting a rename.
authorRob Browning <rlb@defaultvalue.org>
Sun, 6 Oct 2013 19:33:35 +0000 (14:33 -0500)
committerRob Browning <rlb@defaultvalue.org>
Tue, 8 Oct 2013 21:31:29 +0000 (16:31 -0500)
Ben Kelly reported a an IOException (permission denied) during "bup
bloom" on Cygwin.  The exception was caused by the attempt to
os.rename(tfname, outfilename) in do_bloom().

This appears to be because Cygwin doesn't allow you to rename a file
while it's still open.  At first, we thought this might be because
bloom.py create() opens tfname, passes the resulting file to ShaBloom,
and then no one ever explicitly closes it.  So if the gc hasn't
collected the ShaBloom object before the rename, we're in trouble.

However, the problem may also have been caused by an unrelated process
scanning the file at the same time.

In any case, for the moment, explicitly close the ShaBloom object
before the rename.  That shouldn't hurt, and may help.

Thanks to Ben Kelly <btk@google.com> for the report.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
cmd/bloom-cmd.py
lib/bup/bloom.py

index e6a73752dbb9796f1da969cea9d300726f55681f..cd4506d482c2ac8c10f49accee9065bbf314a031 100755 (executable)
@@ -120,6 +120,10 @@ def do_bloom(path, outfilename):
         count += 1
         icount += len(ix)
 
+    # Currently, there's an open file object for tfname inside b.
+    # Make sure it's closed before rename.
+    b.close()
+
     if tfname:
         os.rename(tfname, outfilename)
 
index 5974ee28a70da2d31716cb9f6e2583a2181e0ceb..c90a1fdf40bd812bea35d3ee2d7e28e22a9fc499 100644 (file)
@@ -94,6 +94,9 @@ _total_steps = 0
 bloom_contains = _helpers.bloom_contains
 bloom_add = _helpers.bloom_add
 
+# FIXME: check bloom create() and ShaBloom handling/ownership of "f".
+# The ownership semantics should be clarified since the caller needs
+# to know who is responsible for closing it.
 
 class ShaBloom:
     """Wrapper which contains data from multiple index files. """