Commit 12b21617 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 c2a8e340
...@@ -41,6 +41,7 @@ from ZODB import POSException ...@@ -41,6 +41,7 @@ from ZODB import POSException
from ZODB import utils from ZODB import utils
from ZODB.loglevels import BLATHER from ZODB.loglevels import BLATHER
from ZODB.interfaces import IBlobStorage from ZODB.interfaces import IBlobStorage
from ZODB.blob import rename_or_copy_blob
from persistent.TimeStamp import TimeStamp from persistent.TimeStamp import TimeStamp
logger = logging.getLogger('ZEO.ClientStorage') logger = logging.getLogger('ZEO.ClientStorage')
...@@ -911,22 +912,15 @@ class ClientStorage(object): ...@@ -911,22 +912,15 @@ class ClientStorage(object):
os.close(fd) os.close(fd)
if sys.platform == 'win32': if sys.platform == 'win32':
# On windows, we can't rename to an existing file. We'll
# On windows, we can't rename to an existing file. That's # use a slightly different file name. We keep the old one
# OK. We don't care what file we get as long as it is # until we're done to avoid conflicts. Then remove the old name.
# unique. We'll just keep trying until the rename suceeds. target += 'w'
os.remove(target) rename_or_copy_blob(filename, target)
i = 0 os.remove(target[:-1])
while 1:
try:
utils.rename_or_copy(filename, target + str(i))
except OSError:
i += 1
else: else:
break rename_or_copy_blob(filename, target)
target += str(i)
else:
utils.rename_or_copy(filename, target)
# Now tell the server where we put it # Now tell the server where we put it
self._server.storeBlobShared( self._server.storeBlobShared(
oid, serial, data, oid, serial, data,
...@@ -1182,7 +1176,7 @@ class ClientStorage(object): ...@@ -1182,7 +1176,7 @@ class ClientStorage(object):
targetpath = self.fshelper.getPathForOID(oid) targetpath = self.fshelper.getPathForOID(oid)
if not os.path.exists(targetpath): if not os.path.exists(targetpath):
os.makedirs(targetpath, 0700) os.makedirs(targetpath, 0700)
os.rename(blobfilename, rename_or_copy_blob(blobfilename,
self.fshelper.getBlobFilename(oid, tid), self.fshelper.getBlobFilename(oid, tid),
) )
......
...@@ -492,6 +492,16 @@ class CommonBlobTests: ...@@ -492,6 +492,16 @@ class CommonBlobTests:
self.assert_(os.path.exists(filename)) self.assert_(os.path.exists(filename))
self.assertEqual(somedata, open(filename).read()) 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): def checkLoadBlob(self):
from ZODB.blob import Blob from ZODB.blob import Blob
from ZODB.tests.StorageTestBase import zodb_pickle, ZERO, \ 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