Commit 7ec117d6 authored by Christian Theune's avatar Christian Theune

- removed best_rename, using os.rename again

parent 8c3aa9ee
......@@ -63,7 +63,7 @@ class BlobStorage(ProxyBase):
os.makedirs(targetpath, 0700)
targetname = self._getCleanFilename(oid, serial)
utils.best_rename(blobfilename, targetname)
os.rename(blobfilename, targetname)
# XXX if oid already in there, something is really hosed.
# The underlying storage should have complained anyway
......
......@@ -1205,7 +1205,7 @@ class TmpStore:
os.makedirs(targetpath, 0700)
targetname = self._getCleanFilename(oid, serial)
utils.best_rename(blobfilename, targetname)
os.rename(blobfilename, targetname)
def loadBlob(self, oid, serial, version):
"""Return the filename where the blob file can be found.
......
......@@ -295,27 +295,4 @@ def mktemp():
os.close(handle)
return filename
def best_rename(sourcename, targetname):
""" Try to rename via os.rename, but if we can't (for instance, if the
source and target are on separate partitions/volumes), fall back to copying
the file and unlinking the original. """
try:
os.rename(sourcename, targetname)
except OSError:
# XXX CM: I don't think this is a good idea; maybe just fail
# here instead of doing a brute force copy? This is awfully
# expensive and people won't know it's happening without
# at least a warning. It also increases the possibility of a race
# condition: both the source and target filenames exist at the
# same time.
source = open(sourcename, "rb")
target = open(targetname, "wb")
while True:
chunk = source.read(1<<16)
if not chunk:
break
target.write(chunk)
source.close()
target.close()
os.unlink(sourcename)
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