use a buffer to wait for blob completion
This commit is contained in:
parent
5d69e74010
commit
7262e84150
1 changed files with 9 additions and 7 deletions
|
@ -385,19 +385,21 @@ class BlobFileCreator(HashBlobCreator):
|
||||||
def __init__(self, blob_dir):
|
def __init__(self, blob_dir):
|
||||||
HashBlobCreator.__init__(self)
|
HashBlobCreator.__init__(self)
|
||||||
self.blob_dir = blob_dir
|
self.blob_dir = blob_dir
|
||||||
self.out_file = tempfile.NamedTemporaryFile(delete=False, dir=self.blob_dir)
|
self.buffer = StringIO()
|
||||||
|
|
||||||
def _close(self):
|
def _close(self):
|
||||||
temp_file_name = self.out_file.name
|
|
||||||
self.out_file.close()
|
|
||||||
if self.blob_hash is not None:
|
if self.blob_hash is not None:
|
||||||
shutil.move(temp_file_name, os.path.join(self.blob_dir, self.blob_hash))
|
def _twrite(data, blob_dir, blob_hash):
|
||||||
else:
|
with open(os.path.join(blob_dir, blob_hash), 'w') as out_file:
|
||||||
os.remove(temp_file_name)
|
out_file.write(data.getvalue())
|
||||||
|
d = threads.deferToThread(_twrite, self.buffer,
|
||||||
|
self.blob_dir, self.blob_hash)
|
||||||
|
del self.buffer
|
||||||
|
return d
|
||||||
return defer.succeed(True)
|
return defer.succeed(True)
|
||||||
|
|
||||||
def _write(self, data):
|
def _write(self, data):
|
||||||
self.out_file.write(data)
|
self.buffer.write(data)
|
||||||
|
|
||||||
|
|
||||||
class TempBlobCreator(HashBlobCreator):
|
class TempBlobCreator(HashBlobCreator):
|
||||||
|
|
Loading…
Reference in a new issue