Skip to content

Commit

Permalink
Fix small file upload
Browse files Browse the repository at this point in the history
fixes pulp#535
  • Loading branch information
mdellweg committed Jul 19, 2022
1 parent 2e900c7 commit 5ab9cca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/535.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed uploading file content for files smaller than the chunk size.
5 changes: 3 additions & 2 deletions pulpcore/cli/file/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,14 @@ def upload(
"""Create a file content unit by uploading a file"""
size = os.path.getsize(file.name)
content: Dict[str, Any] = {"relative_path": relative_path}
uploads: Dict[str, IO[bytes]] = {}
if chunk_size > size:
content["file"] = file
uploads["file"] = file
elif pulp_ctx.has_plugin(PluginRequirement("core", min="3.20")):
upload_href = PulpUploadContext(pulp_ctx).upload_file(file, chunk_size)
content["upload"] = upload_href
else:
artifact_href = PulpArtifactContext(pulp_ctx).upload(file, chunk_size)
content["artifact"] = artifact_href
result = entity_ctx.create(body=content)
result = entity_ctx.create(body=content, uploads=uploads)
pulp_ctx.output_result(result)

0 comments on commit 5ab9cca

Please sign in to comment.