Skip to content

Commit 1b5bf09

Browse files
committed
use synchronous endpoint when no repo
1 parent 4c28984 commit 1b5bf09

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

pulp-glue/pulp_glue/rpm/context.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import typing as t
23

34
from pulp_glue.common.context import (
@@ -154,6 +155,60 @@ def list_iterator(
154155
stats=stats,
155156
)
156157

158+
def upload(
159+
self,
160+
file: t.IO[bytes],
161+
chunk_size: int,
162+
repository: t.Optional[PulpRepositoryContext],
163+
**kwargs: t.Any,
164+
) -> t.Any:
165+
"""
166+
Create an RPM package by uploading a file.
167+
168+
This function is deprecated. The create call can handle the upload logic transparently.
169+
170+
Parameters:
171+
file: A file like object that supports `os.path.getsize`.
172+
chunk_size: Size of the chunks to upload independently.
173+
repository: Repository context to add the newly created content to.
174+
kwargs: Extra args specific to the content type, passed to the create call.
175+
176+
Returns:
177+
The result of the create task.
178+
"""
179+
self.needs_capability("upload")
180+
size = os.path.getsize(file.name)
181+
body: t.Dict[str, t.Any] = {**kwargs}
182+
183+
if not self.pulp_ctx.fake_mode:
184+
if chunk_size > size:
185+
# Small file: direct upload
186+
body["file"] = file
187+
else:
188+
# Large file: chunked upload
189+
if self.pulp_ctx.has_plugin(PluginRequirement("core", specifier=">=3.20.0")):
190+
from pulp_glue.core.context import PulpUploadContext
191+
192+
upload_href = PulpUploadContext(self.pulp_ctx).upload_file(file, chunk_size)
193+
body["upload"] = upload_href
194+
else:
195+
from pulp_glue.core.context import PulpArtifactContext
196+
197+
artifact_href = PulpArtifactContext(self.pulp_ctx).upload(file, chunk_size)
198+
body["artifact"] = artifact_href
199+
200+
# For rpm plugin >= 3.32.5, use synchronous upload endpoint when no repository is provided
201+
# For older versions, always use the create endpoint (backward compatibility)
202+
if repository is None and self.pulp_ctx.has_plugin(
203+
PluginRequirement("rpm", specifier=">=3.32.5")
204+
):
205+
return self.call("upload", body=body)
206+
207+
# Repository is specified or older rpm version: use create endpoint (async path)
208+
if repository is not None:
209+
body["repository"] = repository
210+
return self.create(body=body)
211+
157212

158213
class PulpRpmAdvisoryContext(PulpContentContext):
159214
PLUGIN = "rpm"

0 commit comments

Comments
 (0)