[Checkins] SVN: ZODB/branches/jim-zeo-blob/src/ZEO/ClientStorage.py Added work around for fact that you can't rename to an existing file

Jim Fulton jim at zope.com
Thu May 17 18:59:19 EDT 2007


Log message for revision 75824:
  Added work around for fact that you can't rename to an existing file
  on Windows.
  

Changed:
  U   ZODB/branches/jim-zeo-blob/src/ZEO/ClientStorage.py

-=-
Modified: ZODB/branches/jim-zeo-blob/src/ZEO/ClientStorage.py
===================================================================
--- ZODB/branches/jim-zeo-blob/src/ZEO/ClientStorage.py	2007-05-17 22:23:14 UTC (rev 75823)
+++ ZODB/branches/jim-zeo-blob/src/ZEO/ClientStorage.py	2007-05-17 22:59:19 UTC (rev 75824)
@@ -21,6 +21,7 @@
 import cPickle
 import os
 import socket
+import sys
 import tempfile
 import threading
 import time
@@ -909,7 +910,24 @@
             os.mkdir(dir)
         fd, target = self.fshelper.blob_mkstemp(oid, serial)
         os.close(fd)
-        os.rename(filename, target)
+
+        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:
+                    os.rename(filename, target + str(i))
+                except OSError:
+                    i += 1
+                else:
+                    break
+            target += str(i)
+        else:
+            os.rename(filename, target)
         # Now tell the server where we put it
         self._server.storeBlobShared(
             oid, serial, data,



More information about the Checkins mailing list