Skip to content

Commit

Permalink
fix: disable hashes cache for local files (#2019)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming authored Jun 14, 2023
1 parent 4a74bac commit 739d495
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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

0 comments on commit 739d495

Please sign in to comment.