[Zodb-checkins] SVN: ZODB/trunk/src/Z Committed files are read-only.

Jim Fulton jim at zope.com
Sun Jun 10 16:25:43 EDT 2007


Log message for revision 76596:
  Committed files are read-only.
  

Changed:
  U   ZODB/trunk/src/ZEO/ClientStorage.py
  U   ZODB/trunk/src/ZEO/tests/testZEO.py
  U   ZODB/trunk/src/ZODB/blob.py
  U   ZODB/trunk/src/ZODB/tests/blob_transaction.txt

-=-
Modified: ZODB/trunk/src/ZEO/ClientStorage.py
===================================================================
--- ZODB/trunk/src/ZEO/ClientStorage.py	2007-06-10 20:25:36 UTC (rev 76595)
+++ ZODB/trunk/src/ZEO/ClientStorage.py	2007-06-10 20:25:42 UTC (rev 76596)
@@ -21,6 +21,7 @@
 import cPickle
 import os
 import socket
+import stat
 import sys
 import tempfile
 import threading
@@ -952,6 +953,7 @@
     def receiveBlobStop(self, oid, serial):
         blob_filename = self.fshelper.getBlobFilename(oid, serial)
         os.rename(blob_filename+'.dl', blob_filename)
+        os.chmod(blob_filename, stat.S_IREAD)
 
     def loadBlob(self, oid, serial):
 

Modified: ZODB/trunk/src/ZEO/tests/testZEO.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/testZEO.py	2007-06-10 20:25:36 UTC (rev 76595)
+++ ZODB/trunk/src/ZEO/tests/testZEO.py	2007-06-10 20:25:42 UTC (rev 76596)
@@ -21,6 +21,7 @@
 import random
 import signal
 import socket
+import stat
 import tempfile
 import threading
 import time
@@ -532,6 +533,8 @@
 
         filename = self._storage.loadBlob(oid, serial)
         self.assertEquals(somedata, open(filename, 'rb').read())
+        self.assert_(not(os.stat(filename).st_mode & stat.S_IWRITE))
+        self.assert_((os.stat(filename).st_mode & stat.S_IREAD))
 
     def checkTemporaryDirectory(self):
         self.assertEquals(self.blob_cache_dir,

Modified: ZODB/trunk/src/ZODB/blob.py
===================================================================
--- ZODB/trunk/src/ZODB/blob.py	2007-06-10 20:25:36 UTC (rev 76595)
+++ ZODB/trunk/src/ZODB/blob.py	2007-06-10 20:25:42 UTC (rev 76596)
@@ -18,6 +18,7 @@
 import logging
 import os
 import shutil
+import stat
 import sys
 import tempfile
 import threading
@@ -191,7 +192,7 @@
             os.unlink(target)
 
         try:
-            rename_or_copy_blob(filename, target)
+            rename_or_copy_blob(filename, target, chmod=False)
         except:
             # Recover from the failed consumption: First remove the file, it
             # might exist and mark the pointer to the uncommitted file.
@@ -579,12 +580,14 @@
                 load_result = self.loadBefore(oid, serial_id)
 
                 if load_result is None:
+
                     # There was no previous revision of this blob
                     # object.  The blob was created in the transaction
                     # represented by serial_id.  We copy the blob data
                     # to a new file that references the undo
                     # transaction in case a user wishes to undo this
-                    # undo.
+                    # undo. It would be nice if we had some way to
+                    # link to old blobs.
                     orig_fn = self.fshelper.getBlobFilename(oid, serial_id)
                     new_fn = self.fshelper.getBlobFilename(oid, undo_serial)
                 else:
@@ -608,7 +611,7 @@
 
 
 copied = logging.getLogger('ZODB.blob.copied').debug
-def rename_or_copy_blob(f1, f2):
+def rename_or_copy_blob(f1, f2, chmod=True):
     """Try to rename f1 to f2, fallback to copy.
 
     Under certain conditions a rename might not work, e.g. because the target
@@ -622,3 +625,5 @@
         copied("Copied blob file %r to %r.", f1, f2)
         utils.cp(open(f1, 'rb'), open(f2, 'wb'))
         os.unlink(f1)
+    if chmod:
+        os.chmod(f2, stat.S_IREAD)

Modified: ZODB/trunk/src/ZODB/tests/blob_transaction.txt
===================================================================
--- ZODB/trunk/src/ZODB/tests/blob_transaction.txt	2007-06-10 20:25:36 UTC (rev 76595)
+++ ZODB/trunk/src/ZODB/tests/blob_transaction.txt	2007-06-10 20:25:42 UTC (rev 76596)
@@ -303,7 +303,12 @@
     >>> open(blob.committed()).read()
     "I'm a happy blob."
 
+You can't open a committed blob file for writing:
 
+    >>> open(blob.committed(), 'w') # doctest: +ELLIPSIS
+    Traceback (most recent call last):
+    ...
+    IOError: ...
 
 
 Teardown



More information about the Zodb-checkins mailing list