[Zope3-checkins] CVS: ZODB4/ZODB - FileStorage.py:1.113

Barry Warsaw barry@wooz.org
Mon, 16 Dec 2002 16:18:39 -0500


Update of /cvs-repository/ZODB4/ZODB
In directory cvs.zope.org:/tmp/cvs-serv8806

Modified Files:
	FileStorage.py 
Log Message:
Forward ported from zodb3, add the cleanup() method and module
function.


=== ZODB4/ZODB/FileStorage.py 1.112 => 1.113 ===
--- ZODB4/ZODB/FileStorage.py:1.112	Wed Dec 11 18:40:50 2002
+++ ZODB4/ZODB/FileStorage.py	Mon Dec 16 16:18:39 2002
@@ -720,8 +720,14 @@
         # - data can be None, which indicates a George Bailey object
         #   (i.e. one who's creation has been transactionally undone).
         #
-        # If prev_txn is not None, it should contain the same data as
-        # the argument data.  If it does, write a backpointer to it.
+        # prev_txn is a backpointer.  In the original database, it's possible
+        # that the data was actually living in a previous transaction.  This
+        # can happen for transactional undo and other operations, and is used
+        # as a space saving optimization.  Under some circumstances the
+        # prev_txn may not actually exist in the target database (i.e. self)
+        # for example, if it's been packed away.  In that case, the prev_txn
+        # should be considered just a hint, and is ignored if the transaction
+        # doesn't exist.
         if self._is_read_only:
             raise POSException.ReadOnlyError()
         if transaction is not self._transaction:
@@ -1365,6 +1371,11 @@
             raise CorruptedDataError(oid, h)
         return h[8:]
 
+    def cleanup(self):
+        """Remove all files created by this storage."""
+        cleanup(self._file_name)
+
+
 class FileStoragePacker(FileStorageFormatter):
 
     def __init__(self, path, stop, la, lr, cla, clr):
@@ -2324,3 +2335,13 @@
     def parseVersion(self, buf):
         self.pnv, self.vprev = struct.unpack(">QQ", buf[:16])
         self.version = buf[16:]
+
+
+def cleanup(filename):
+    """Remove all FileStorage related files."""
+    for ext in '', '.old', '.tmp', '.lock', '.index', '.pack':
+        try:
+            os.remove(filename + ext)
+        except OSError, e:
+            if e.errno != errno.ENOENT:
+                raise