forked from LBRYCommunity/lbry-sdk
fix empty tail blobs in stream from being saved
This commit is contained in:
parent
6f71a5003c
commit
e046af57fa
1 changed files with 10 additions and 2 deletions
|
@ -27,13 +27,21 @@ class BlobFileCreator(object):
|
||||||
def close(self):
|
def close(self):
|
||||||
self.length = self.len_so_far
|
self.length = self.len_so_far
|
||||||
self.blob_hash = self._hashsum.hexdigest()
|
self.blob_hash = self._hashsum.hexdigest()
|
||||||
if self.blob_hash and self._is_open:
|
if self.blob_hash and self._is_open and self.length > 0:
|
||||||
|
# do not save 0 length files (empty tail blob in streams)
|
||||||
|
# or if its been closed already
|
||||||
self.buffer.seek(0)
|
self.buffer.seek(0)
|
||||||
out_path = os.path.join(self.blob_dir, self.blob_hash)
|
out_path = os.path.join(self.blob_dir, self.blob_hash)
|
||||||
producer = FileBodyProducer(self.buffer)
|
producer = FileBodyProducer(self.buffer)
|
||||||
yield producer.startProducing(open(out_path, 'wb'))
|
yield producer.startProducing(open(out_path, 'wb'))
|
||||||
self._is_open = False
|
self._is_open = False
|
||||||
|
if self.length > 0:
|
||||||
defer.returnValue(self.blob_hash)
|
defer.returnValue(self.blob_hash)
|
||||||
|
else:
|
||||||
|
# 0 length files (empty tail blob in streams )
|
||||||
|
# must return None as their blob_hash for
|
||||||
|
# it to be saved properly by EncryptedFileMetadataManagers
|
||||||
|
defer.returnValue(None)
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
if not self._is_open:
|
if not self._is_open:
|
||||||
|
|
Loading…
Reference in a new issue