Skip to content

Commit

Permalink
Fix for cases where downloaded file size is different than expected. …
Browse files Browse the repository at this point in the history
…For #709 (#710)

When a file was downloaded successfully, but the size was different than in the message, or the message didn't include a file size, still rename the file and patch content_type.
  • Loading branch information
reidsunderland authored Jun 27, 2023
1 parent 910ab55 commit 2d943ca
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions sarracenia/flow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1835,13 +1835,6 @@ def download(self, msg, options) -> bool:
if not self.o.dry_run:
if accelerated:
self.proto[self.scheme].update_file(new_inflight_path)
if (new_inflight_path != new_file):
if os.path.isfile(new_file):
os.remove(new_file)
os.rename(new_inflight_path, new_file)
# older versions don't include the contentType, so patch it here.
if 'contentType' not in msg:
msg['contentType'] = magic.from_file(new_file,mime=True)
elif len_written < 0:
logger.error("failed to download %s" % new_file)
return False
Expand All @@ -1865,8 +1858,18 @@ def download(self, msg, options) -> bool:
'incomplete download only %d of expected %d bytes for %s'
% (len_written, block_length, new_inflight_path))
return False

msg['size'] = len_written
# when len_written is different than block_length
msg['size'] = len_written

# if we haven't returned False by this point, assuming download was successful
if (new_inflight_path != new_file):
if os.path.isfile(new_file):
os.remove(new_file)
os.rename(new_inflight_path, new_file)

# older versions don't include the contentType, so patch it here.
if 'contentType' not in msg:
msg['contentType'] = magic.from_file(new_file,mime=True)

self.metrics['flow']['transferRxBytes'] += len_written
self.metrics['flow']['transferRxFiles'] += 1
Expand Down

0 comments on commit 2d943ca

Please sign in to comment.