Fix a bug with torrent calculation on duplicate v2 uploads

This commit is contained in:
Jake Moshenko 2016-01-08 15:06:33 -05:00
parent 932d892276
commit 17d3b5e204

View file

@ -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)