Skip to content

Commit

Permalink
Minor chunk upload improvements.
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
ipanova committed Jun 14, 2022
1 parent 1d1cea4 commit d72d1ef
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pulpcore/app/models/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ def append(self, chunk, offset, sha256=None):
offset (int): First byte position to write chunk to.
"""
chunk_read = chunk.read()
current_sha256 = hashlib.sha256(chunk_read).hexdigest()
if sha256 and sha256 != current_sha256:
raise serializers.ValidationError("Checksum does not match chunk upload.")
if sha256:
current_sha256 = hashlib.sha256(chunk_read).hexdigest()
if sha256 != current_sha256:
raise serializers.ValidationError("Checksum does not match chunk upload.")

upload_chunk = UploadChunk(upload=self, offset=offset, size=len(chunk))
upload_chunk = UploadChunk(upload=self, offset=offset, size=len(chunk_read))
filename = os.path.basename(upload_chunk.storage_path(""))
upload_chunk.file.save(filename, ContentFile(chunk_read))

Expand Down

0 comments on commit d72d1ef

Please sign in to comment.