Commit f9974723 authored by Jim Fulton's avatar Jim Fulton

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.
parent 06be0b34
......@@ -41,6 +41,7 @@ from ZODB import POSException
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 @@ class ClientStorage(object):
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 @@ class ClientStorage(object):
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),
)
......
......@@ -492,6 +492,16 @@ class CommonBlobTests:
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, \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment