Skip to content

Commit abcbb67

Browse files
committed
Fixes how package names are stored.
Closes #315 (cherry picked from commit 5ff0ca6)
1 parent 51f74d3 commit abcbb67

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

CHANGES/315.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes the name of the package when downloaded using pull-through cache.

pulp_npm/app/models.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,16 @@ def content_handler(self, path):
112112
repository_version = self.repository.latest_version()
113113

114114
content = repository_version.content
115-
packages = Package.objects.filter(name=path, pk__in=content)
115+
name, version = extract_package_info(path)
116+
if name and version:
117+
return None
118+
119+
packages = Package.objects.filter(name=name, pk__in=content)
116120

117121
if not packages:
118122
return None
119123

120-
data["name"] = path
124+
data["name"] = name
121125
data["versions"] = {}
122126
versions = []
123127

@@ -140,7 +144,7 @@ def content_handler(self, path):
140144
)
141145

142146
for package in packages:
143-
tarball_url = f"{prefix_url}{package.relative_path.split('/')[-1]}"
147+
tarball_url = f"{prefix_url}{package.name}/-/{package.relative_path.split('/')[-1]}"
144148

145149
version = {
146150
package.version: {

pulp_npm/app/tasks/synchronizing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async def run(self):
104104
da = DeclarativeArtifact(
105105
artifact=artifact,
106106
url=url,
107-
relative_path=url.split("/")[-1],
107+
relative_path=f"{pkg['name']}/-/{url.split('/')[-1]}",
108108
remote=self.remote,
109109
deferred_download=self.deferred_download,
110110
)

pulp_npm/app/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def extract_package_info(relative_path):
2828
Args:
2929
The relative_path string. "package/-/package-version.tgz"
3030
"""
31-
pattern = r"^(?P<name>@?[^/]+(?:/[^/]+)?)/-/(?P<base_name>[^/]+)-(?P<version>[\d.]+)\.tgz$"
31+
pattern = r"^(?P<name>@?[^/]+(?:/[^/]+)?)(?:/-/(?P<base_name>[^/]+)-(?P<version>[\d.]+)\.tgz)?$"
3232
match = re.match(pattern, relative_path)
3333

3434
if match:

pulp_npm/tests/functional/api/test_download_content.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ def test_download_content(
5757

5858
fixture_hash = hashlib.sha256(http_get(urljoin(NPM_FIXTURE_URL, unit_path))).hexdigest()
5959

60-
pulp_hash = hashlib.sha256(
61-
http_get(urljoin(distribution.base_url, unit_path.split("/")[-1]))
62-
).hexdigest()
60+
pulp_hash = hashlib.sha256(http_get(urljoin(distribution.base_url, unit_path))).hexdigest()
6361

6462
assert fixture_hash == pulp_hash
6563

0 commit comments

Comments
 (0)