[Zodb-checkins] CVS: Zope/lib/python/ZODB - FileStorage.py:1.98.2.1
Jeremy Hylton
jeremy@zope.com
Tue, 5 Nov 2002 16:23:50 -0500
Update of /cvs-repository/Zope/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv7815/lib/python/ZODB
Modified Files:
Tag: Zope-2_6-branch
FileStorage.py
Log Message:
Backport several bug fixes:
- Fix for George Bailey events
- restore() writes backpointers when possible
- Add data_txn hint to iterator()
=== Zope/lib/python/ZODB/FileStorage.py 1.98 => 1.98.2.1 === (728/828 lines abridged)
--- Zope/lib/python/ZODB/FileStorage.py:1.98 Wed Aug 28 14:19:13 2002
+++ Zope/lib/python/ZODB/FileStorage.py Tue Nov 5 16:23:49 2002
@@ -148,11 +148,17 @@
register_subsystem('ZODB FS')
z64='\0'*8
+# the struct formats for the headers
+TRANS_HDR = ">8s8scHHH"
+DATA_HDR = ">8s8s8s8sH8s"
# constants to support various header sizes
TRANS_HDR_LEN = 23
DATA_HDR_LEN = 42
DATA_VERSION_HDR_LEN = 58
+assert struct.calcsize(TRANS_HDR) == TRANS_HDR_LEN
+assert struct.calcsize(DATA_HDR) == DATA_HDR_LEN
+
def warn(message, *data):
LOG('ZODB FS', WARNING, "%s warn: %s\n" % (packed_version,
(message % data)))
@@ -175,21 +181,19 @@
class FileStorageFormatError(FileStorageError):
"""Invalid file format
- The format of the given file is not valid
+ The format of the given file is not valid.
"""
class CorruptedFileStorageError(FileStorageError,
POSException.StorageSystemError):
- """Corrupted file storage
- """
+ """Corrupted file storage."""
class CorruptedTransactionError(CorruptedFileStorageError): pass
class CorruptedDataError(CorruptedFileStorageError): pass
class FileStorageQuotaError(FileStorageError,
POSException.StorageSystemError):
- """File storage quota exceeded
- """
+ """File storage quota exceeded."""
packed_version='FS21'
@@ -365,7 +369,7 @@
if pos < 4: return 0
seek(pos)
s = read(TRANS_HDR_LEN)
- tid, stl, status, ul, dl, el = unpack(">8s8scHHH", s)
[-=- -=- -=- 728 lines omitted -=- -=- -=-]
+ self.packt = packt
+ self.first = first
+ self.last = last
+ self.filter = filter
+ self.i = 0
+ self.results = []
+ self.stop = 0
+
+ def finished(self):
+ """Return True if UndoSearch has found enough records."""
+ # BAW: Why 39 please? This makes no sense (see also below).
+ return self.i >= self.last or self.pos < 39 or self.stop
+
+ def search(self):
+ """Search for another record."""
+ dict = self._readnext()
+ if dict is not None and (self.filter is None or self.filter(dict)):
+ if self.i >= self.first:
+ self.results.append(dict)
+ self.i += 1
+
+ def _readnext(self):
+ """Read the next record from the storage."""
+ self.file.seek(self.pos - 8)
+ self.pos -= U64(self.file.read(8)) + 8
+ self.file.seek(self.pos)
+ h = self.file.read(TRANS_HDR_LEN)
+ tid, tl, status, ul, dl, el = struct.unpack(TRANS_HDR, h)
+ if tid < self.packt or status == 'p':
+ self.stop = 1
+ return None
+ if status != ' ':
+ return None
+ d = u = ''
+ if ul:
+ u = self.file.read(ul)
+ if dl:
+ d = self.file.read(dl)
+ e = {}
+ if el:
+ try:
+ e = loads(self.file.read(el))
+ except:
+ pass
+ d = {'id': base64.encodestring(tid).rstrip(),
+ 'time': TimeStamp(tid).timeTime(),
+ 'user_name': u,
+ 'description': d}
+ d.update(e)
+ return d