Skip to content
Closed
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
55 changes: 55 additions & 0 deletions pulp-glue/pulp_glue/rpm/context.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import typing as t

from pulp_glue.common.context import (
Expand Down Expand Up @@ -154,6 +155,60 @@ def list_iterator(
stats=stats,
)

def upload(
self,
file: t.IO[bytes],
chunk_size: int,
repository: t.Optional[PulpRepositoryContext],
**kwargs: t.Any,
) -> t.Any:
"""
Create an RPM package by uploading a file.

This function is deprecated. The create call can handle the upload logic transparently.

Parameters:
file: A file like object that supports `os.path.getsize`.
chunk_size: Size of the chunks to upload independently.
repository: Repository context to add the newly created content to.
kwargs: Extra args specific to the content type, passed to the create call.

Returns:
The result of the create task.
"""
self.needs_capability("upload")
size = os.path.getsize(file.name)
body: t.Dict[str, t.Any] = {**kwargs}

if not self.pulp_ctx.fake_mode:
if chunk_size > size:
# Small file: direct upload
body["file"] = file
else:
# Large file: chunked upload
if self.pulp_ctx.has_plugin(PluginRequirement("core", specifier=">=3.20.0")):
from pulp_glue.core.context import PulpUploadContext

upload_href = PulpUploadContext(self.pulp_ctx).upload_file(file, chunk_size)
body["upload"] = upload_href
else:
from pulp_glue.core.context import PulpArtifactContext

artifact_href = PulpArtifactContext(self.pulp_ctx).upload(file, chunk_size)
body["artifact"] = artifact_href

# For rpm plugin >= 3.32.5, use synchronous upload endpoint when no repository is provided
# For older versions, always use the create endpoint (backward compatibility)
if repository is None and self.pulp_ctx.has_plugin(
PluginRequirement("rpm", specifier=">=3.32.5")
):
return self.call("upload", body=body)

# Repository is specified or older rpm version: use create endpoint (async path)
if repository is not None:
body["repository"] = repository
return self.create(body=body)


class PulpRpmAdvisoryContext(PulpContentContext):
PLUGIN = "rpm"
Expand Down
Loading