[Zodb-checkins] CVS: StandaloneZODB/ZODB - FileStorage.py:1.76.8.5
Jeremy Hylton
jeremy@zope.com
Mon, 7 Jan 2002 18:04:41 -0500
Update of /cvs-repository/StandaloneZODB/ZODB
In directory cvs.zope.org:/tmp/cvs-serv8272/ZODB
Modified Files:
Tag: Standby-branch
FileStorage.py
Log Message:
Implement isReadOnly() for FileStorage.
A FileStorage now raises ReadOnlyError when an update is attempted on
a read_only storage. It used to fail with an IOError when an attempt
was made to write() a read-only file.
=== StandaloneZODB/ZODB/FileStorage.py 1.76.8.4 => 1.76.8.5 ===
if read_only:
+ self._is_read_only = 1
if create:
raise ValueError, "can\'t create a read-only file"
elif stop is not None:
@@ -408,6 +409,8 @@
def commitVersion(self, src, dest, transaction, abort=None):
# We are going to commit by simply storing back pointers.
+ if self._is_read_only:
+ raise POSException.ReadOnlyError()
if not (src and isinstance(src, StringType)
and isinstance(dest, StringType)):
raise POSException.VersionCommitError('Invalid source version')
@@ -618,6 +621,8 @@
finally: self._lock_release()
def store(self, oid, serial, data, version, transaction):
+ if self._is_read_only:
+ raise POSException.ReadOnlyError()
if transaction is not self._transaction:
raise POSException.StorageTransactionError(self, transaction)
@@ -683,8 +688,11 @@
finally:
self._lock_release()
- def supportsUndo(self): return 1
- def supportsVersions(self): return 1
+ def supportsUndo(self):
+ return 1
+
+ def supportsVersions(self):
+ return 1
def _clear_temp(self):
self._tindex.clear()
@@ -773,6 +781,8 @@
self._nextpos=0
def undo(self, transaction_id):
+ if self._is_read_only:
+ raise POSException.ReadOnlyError()
self._lock_acquire()
try:
self._clear_index()
@@ -820,7 +830,8 @@
return t.keys()
finally: self._lock_release()
- def supportsTransactionalUndo(self): return 1
+ def supportsTransactionalUndo(self):
+ return 1
def _undoDataInfo(self, oid, pos, tpos):
"""Return the serial, data pointer, data, and version for the oid
@@ -942,7 +953,9 @@
# writing a file position rather than a pickle. Sometimes, we
# may do conflict resolution, in which case we actually copy
# new data that results from resolution.
-
+
+ if self._is_read_only:
+ raise POSException.ReadOnlyError()
if transaction is not self._transaction:
raise POSException.StorageTransactionError(self, transaction)
@@ -1187,6 +1200,8 @@
the associated data are copied, since the old records are not copied.
"""
+ if self._is_read_only:
+ raise POSException.ReadOnlyError()
# Ugh, this seems long
packing=1 # are we in the packing phase (or the copy phase)