Skip to content

Commit 3fe968a

Browse files
authored
Merge pull request #218 from cariad-tech/feat/cache_hashes
fix: Use hash to cache files
2 parents 2d98cd3 + 19a3ec3 commit 3fe968a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/python_inspector/utils_pypi.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#
1111
import asyncio
1212
import email
13+
import hashlib
1314
import itertools
1415
import os
1516
import pathlib
@@ -1678,6 +1679,9 @@ class Cache:
16781679
def __attrs_post_init__(self):
16791680
os.makedirs(self.directory, exist_ok=True)
16801681

1682+
def sha256_hash(self, text: str) -> str:
1683+
return hashlib.sha256(text.encode()).hexdigest()
1684+
16811685
async def get(
16821686
self,
16831687
credentials,
@@ -1693,7 +1697,7 @@ async def get(
16931697
True otherwise as treat as binary. `path_or_url` can be a path or a URL
16941698
to a file.
16951699
"""
1696-
cache_key = quote_plus(path_or_url.strip("/"))
1700+
cache_key = self.sha256_hash(quote_plus(path_or_url.strip("/")))
16971701
cached = os.path.join(self.directory, cache_key)
16981702

16991703
if force or not os.path.exists(cached):

0 commit comments

Comments
 (0)