Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix continuation for started large files with no fully finished parts #530

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions b2sdk/_internal/transfer/emerge/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ def _find_matching_unfinished_file(
continue

finished_parts = {}
conflict_detected = False

for part in self.services.large_file.list_parts(file_.file_id):
emerge_part = emerge_parts_dict.get(part.part_number)
Expand All @@ -405,33 +406,33 @@ def _find_matching_unfinished_file(
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 @@ -2006,7 +2006,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 @@ -906,7 +906,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
Loading