[Zodb-checkins] SVN: ZODB/trunk/src/ZEO/ Changed _storeBlob_shared to reflect the fact that we're now copying

Jim Fulton jim at zope.com
Sun Jun 10 14:25:07 EDT 2007


Log message for revision 76584:
  Changed _storeBlob_shared to reflect the fact that we're now copying
  if we can't link.
  
  Added support for copying to blob cache when renaming fails.
  

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

-=-
Modified: ZODB/trunk/src/ZEO/ClientStorage.py
===================================================================
--- ZODB/trunk/src/ZEO/ClientStorage.py	2007-06-10 18:21:16 UTC (rev 76583)
+++ ZODB/trunk/src/ZEO/ClientStorage.py	2007-06-10 18:25:06 UTC (rev 76584)
@@ -41,6 +41,7 @@
 from ZODB import utils
 from ZODB.loglevels import BLATHER
 from ZODB.interfaces import IBlobStorage
+from ZODB.blob import rename_or_copy_blob
 from persistent.TimeStamp import TimeStamp
 
 logger = logging.getLogger('ZEO.ClientStorage')
@@ -911,22 +912,15 @@
         os.close(fd)
 
         if sys.platform == 'win32':
-
-            # On windows, we can't rename to an existing file.  That's
-            # OK.  We don't care what file we get as long as it is
-            # unique.  We'll just keep trying until the rename suceeds.
-            os.remove(target)
-            i = 0
-            while 1:
-                try:
-                    utils.rename_or_copy(filename, target + str(i))
-                except OSError:
-                    i += 1
-                else:
-                    break
-            target += str(i)
+            # On windows, we can't rename to an existing file.  We'll
+            # use a slightly different file name. We keep the old one
+            # until we're done to avoid conflicts. Then remove the old name.
+            target += 'w'
+            rename_or_copy_blob(filename, target)
+            os.remove(target[:-1])
         else:
-            utils.rename_or_copy(filename, target)
+            rename_or_copy_blob(filename, target)
+
         # Now tell the server where we put it
         self._server.storeBlobShared(
             oid, serial, data,
@@ -1182,7 +1176,7 @@
                 targetpath = self.fshelper.getPathForOID(oid)
                 if not os.path.exists(targetpath):
                     os.makedirs(targetpath, 0700)
-                os.rename(blobfilename,
+                rename_or_copy_blob(blobfilename,
                           self.fshelper.getBlobFilename(oid, tid),
                           )
 

Modified: ZODB/trunk/src/ZEO/tests/testZEO.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/testZEO.py	2007-06-10 18:21:16 UTC (rev 76583)
+++ ZODB/trunk/src/ZEO/tests/testZEO.py	2007-06-10 18:25:06 UTC (rev 76584)
@@ -492,6 +492,16 @@
         self.assert_(os.path.exists(filename))
         self.assertEqual(somedata, open(filename).read())
 
+    def checkStoreBlob_wrong_partition(self):
+        os_rename = os.rename
+        try:
+            def fail(*a):
+                raise OSError
+            os.rename = fail
+            self.checkStoreBlob()
+        finally:
+            os.rename = os_rename
+
     def checkLoadBlob(self):
         from ZODB.blob import Blob
         from ZODB.tests.StorageTestBase import zodb_pickle, ZERO, \



More information about the Zodb-checkins mailing list