Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable hashes cache for local files #2019

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions news/2019.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable hashes caching for local files.
9 changes: 8 additions & 1 deletion src/pdm/models/caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from cachecontrol.cache import SeparateBodyBaseCache
from cachecontrol.caches import FileCache
from packaging.utils import canonicalize_name, parse_wheel_filename

from pdm._types import CandidateInfo
from pdm.exceptions import PdmException
from pdm.models.candidates import Candidate
Expand Down Expand Up @@ -128,6 +129,11 @@ def _get_file_hash(self, link: Link, session: Session) -> str:
h.update(chunk)
return ":".join([h.name, h.hexdigest()])

def _should_cache(self, link: Link) -> bool:
# For now, we only disable caching for local files.
# We may add more when we know better about it.
return not link.is_file

def get_hash(self, link: Link, session: Session) -> str:
# If there is no link hash (i.e., md5, sha256, etc.), we don't want
# to store it.
Expand All @@ -142,7 +148,8 @@ def get_hash(self, link: Link, session: Session) -> str:
hash_value = f"{link.hash_name}:{link.hash}"
else:
hash_value = self._get_file_hash(link, session)
self.set(link.url_without_fragment, hash_value)
if self._should_cache(link):
self.set(link.url_without_fragment, hash_value)
return hash_value

def _get_path_for_key(self, key: str) -> Path:
Expand Down