[Zope3-checkins] CVS: ZODB/src/ZODB/FileStorage - fspack.py:1.13

Tim Peters tim.one at comcast.net
Tue Mar 30 16:53:46 EST 2004


Update of /cvs-repository/ZODB/src/ZODB/FileStorage
In directory cvs.zope.org:/tmp/cvs-serv8862/src/ZODB/FileStorage

Modified Files:
	fspack.py 
Log Message:
FileStoragePacker:  the change yesterday to speed packing by doing most
of pack in buffered mode, then switching to unbuffered mode to copy the
tail, actually broke pack completely on Windows:  we didn't close the
buffered file handle before opening the unbuffered one, and self.gc held
on to the still-open former handle.  This prevented the caller from
renaming Data.fs to Data.fs.old (a handle on Data.fs was still open).
The cure is simply to close a handle when we stop using it.


=== ZODB/src/ZODB/FileStorage/fspack.py 1.12 => 1.13 ===
--- ZODB/src/ZODB/FileStorage/fspack.py:1.12	Mon Mar 29 21:43:25 2004
+++ ZODB/src/ZODB/FileStorage/fspack.py	Tue Mar 30 16:53:40 2004
@@ -416,6 +416,10 @@
     # progress after it).
     def __init__(self, path, stop, la, lr, cla, clr, current_size):
         self._name = path
+        # We open our own handle on the storage so that much of pack can
+        # proceed in parallel.  It's important to close this file at every
+        # return point, else on Windows the caller won't be able to rename
+        # or remove the storage file.
         self._file = open(path, "rb")
         self._path = path
         self._stop = stop
@@ -481,6 +485,7 @@
         if ipos == opos:
             # pack didn't free any data.  there's no point in continuing.
             self._tfile.close()
+            self._file.close()
             os.remove(self._name + ".pack")
             return None
         self._commit_lock_acquire()
@@ -499,6 +504,7 @@
             # trailing 0 argument, and then on every platform except
             # native Windows it was observed that we could read stale
             # data from the tail end of the file.
+            self._file.close()  # else self.gc keeps the original alive & open
             self._file = open(self._path, "rb", 0)
             self._file.seek(0, 2)
             self.file_end = self._file.tell()




More information about the Zope3-Checkins mailing list