From 17d3b5e204cfc2b4715108161f483027b3aa315e Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Fri, 8 Jan 2016 15:06:33 -0500 Subject: [PATCH] Fix a bug with torrent calculation on duplicate v2 uploads --- endpoints/v2/blob.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/endpoints/v2/blob.py b/endpoints/v2/blob.py index adc59269c..d8b1c9844 100644 --- a/endpoints/v2/blob.py +++ b/endpoints/v2/blob.py @@ -275,7 +275,8 @@ def _finish_upload(namespace, repo_name, upload_obj, expected_digest): # Move the storage into place, or if this was a re-upload, cancel it with database.CloseForLongOperation(app.config): - if storage.exists({upload_obj.location.name}, final_blob_location): + already_exists = storage.exists({upload_obj.location.name}, final_blob_location) + if already_exists: # It already existed, clean up our upload which served as proof that we had the file storage.cancel_chunked_upload({upload_obj.location.name}, upload_obj.uuid, upload_obj.storage_metadata) @@ -293,7 +294,7 @@ def _finish_upload(namespace, repo_name, upload_obj, expected_digest): app.config['PUSH_TEMP_TAG_EXPIRATION_SEC'], upload_obj.uncompressed_byte_count) - if upload_obj.piece_sha_state is not None: + if upload_obj.piece_sha_state is not None and not already_exists: piece_bytes = upload_obj.piece_hashes + upload_obj.piece_sha_state.digest() model.storage.save_torrent_info(blob_storage, app.config['TORRENT_PIECE_SIZE'], piece_bytes)