Skip to content

Commit

Permalink
Merge pull request #388 from reef-technologies/fix-incremental-mode
Browse files Browse the repository at this point in the history
Fix continuation for started large files with no fully finished parts
  • Loading branch information
olzhasar-reef authored Dec 23, 2024
2 parents 3e1ae49 + 355f568 commit 030e4b9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
15 changes: 8 additions & 7 deletions b2sdk/_internal/transfer/emerge/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def _find_matching_unfinished_file(
continue

finished_parts = {}
conflict_detected = False

for part in self.services.large_file.list_parts(file_.file_id):

Expand All @@ -401,33 +402,33 @@ def _find_matching_unfinished_file(
'Rejecting %s: part %s not found in emerge parts, giving up.',
file_.file_id, part.part_number
)
finished_parts = None
conflict_detected = True
break

# Compare part sizes
if emerge_part.get_length() != part.content_length:
logger.debug(
'Rejecting %s: part %s size mismatch', file_.file_id, part.part_number
)
continue # part size doesn't match - so we reupload
conflict_detected = True
break # part size doesn't match - so we reupload

# Compare part hashes
if emerge_part.is_hashable() and emerge_part.get_sha1() != part.content_sha1:
logger.debug(
'Rejecting %s: part %s sha1 mismatch', file_.file_id, part.part_number
)
continue # part.sha1 doesn't match - so we reupload
conflict_detected = True
break # part.sha1 doesn't match - so we reupload

finished_parts[part.part_number] = part

if finished_parts is None:
if conflict_detected:
continue

finished_parts_len = len(finished_parts)

if finished_parts and (
best_match_file is None or finished_parts_len > best_match_parts_len
):
if best_match_file is None or finished_parts_len > best_match_parts_len:
best_match_file = file_
best_match_parts = finished_parts
best_match_parts_len = finished_parts_len
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+fix_large_file_continuation.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix continuation for started large files with no fully finished parts.
2 changes: 1 addition & 1 deletion test/unit/bucket/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,7 @@ def test_upload_large_resume_no_parts(self):
large_file_id = self._start_large_file('file1')
progress_listener = StubProgressListener()
file_info = self.bucket.upload_bytes(data, 'file1', progress_listener=progress_listener)
self.assertNotEqual(large_file_id, file_info.id_) # it's not a match if there are no parts
self.assertEqual(large_file_id, file_info.id_)
self._check_file_contents('file1', data)
self.assertTrue(progress_listener.is_valid())

Expand Down
2 changes: 1 addition & 1 deletion test/unit/v0/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ def test_upload_large_resume_no_parts(self):
large_file_id = self._start_large_file('file1')
progress_listener = StubProgressListener()
file_info = self.bucket.upload_bytes(data, 'file1', progress_listener=progress_listener)
self.assertNotEqual(large_file_id, file_info.id_) # it's not a match if there are no parts
self.assertEqual(large_file_id, file_info.id_)
self._check_file_contents('file1', data)
self.assertTrue(progress_listener.is_valid())

Expand Down

0 comments on commit 030e4b9

Please sign in to comment.