Commit ee567a72 by Riccardo Albertazzi Committed by GitHub

fix: fix url dependency caching when special urlencoded chars (#7921)

parent e5bbc604
from __future__ import annotations from __future__ import annotations
import functools import functools
import os
import urllib.parse
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
...@@ -77,20 +75,19 @@ class DirectOrigin: ...@@ -77,20 +75,19 @@ class DirectOrigin:
return PackageInfo.from_directory(path=directory).to_package(root_dir=directory) return PackageInfo.from_directory(path=directory).to_package(root_dir=directory)
def get_package_from_url(self, url: str) -> Package: def get_package_from_url(self, url: str) -> Package:
file_name = os.path.basename(urllib.parse.urlparse(url).path)
link = Link(url) link = Link(url)
artifact = self._artifact_cache.get_cached_archive_for_link(link, strict=True) artifact = self._artifact_cache.get_cached_archive_for_link(link, strict=True)
if not artifact: if not artifact:
artifact = ( artifact = (
self._artifact_cache.get_cache_directory_for_link(link) / file_name self._artifact_cache.get_cache_directory_for_link(link) / link.filename
) )
artifact.parent.mkdir(parents=True, exist_ok=True) artifact.parent.mkdir(parents=True, exist_ok=True)
download_file(url, artifact) download_file(url, artifact)
package = self.get_package_from_file(artifact) package = self.get_package_from_file(artifact)
package.files = [ package.files = [
{"file": file_name, "hash": "sha256:" + get_file_hash(artifact)} {"file": link.filename, "hash": "sha256:" + get_file_hash(artifact)}
] ]
package._source_type = "url" package._source_type = "url"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment