]> arthur.barton.de Git - bup.git/commitdiff
Don't try to rename tmpfiles into existing open files.
authorLukasz Kosewski <lkosewsk@gmail.com>
Sun, 10 Jan 2010 09:04:17 +0000 (04:04 -0500)
committerLukasz Kosewski <lkosewsk@gmail.com>
Sun, 10 Jan 2010 09:04:17 +0000 (04:04 -0500)
Linux and friends have no problem with this, but Windows doesn't allow
this without some effort, which we can avoid by... not needing to write
to an already-open file.

Give index.Reader a 'close' method which identifies and closes any open
mmaped files, and make cmd-index.py use this before trying to close a
index.Writer instance (which renames a tmpfile into the same file the
Reader has mmaped).

cmd-index.py
index.py

index e3d1b7be244f64a28437b71ded1cd5e5a93a0ab1..bf1e5036501305540ca32b786ed9c7321b3a58a1 100755 (executable)
@@ -174,6 +174,7 @@ def update_index(path):
     if wi.count:
         mi = index.Writer(indexfile)
         merge_indexes(mi, ri, wi.new_reader())
+        ri.close()
         mi.close()
     wi.abort()
 
index 9a746eb2ec464ade3411553b37a80d938ac7fae8..3860087042c079eb3e5d7d66358fc87a3a2891e6 100644 (file)
--- a/index.py
+++ b/index.py
@@ -94,7 +94,7 @@ class Reader:
                 self.writable = True
 
     def __del__(self):
-        self.save()
+        self.close()
 
     def __iter__(self):
         tstart = int(time.time())
@@ -110,6 +110,12 @@ class Reader:
         if self.writable:
             self.m.flush()
 
+    def close(self):
+        self.save()
+        if self.writable:
+            self.m.close()
+            self.writable = False
+
     def filter(self, prefixes):
         #log("filtering %r\n" % prefixes)
         paths = reduce_paths(prefixes)