Skip to content

Commit 19a3ec3

Browse files
committed
fix: Use hash to cache files
When alternative registries have long names, possible path can explode on file system limitation., causing python-inspector raise an exception and bail out. Using a simple hash will keep the issue contained. Signed-off-by: Helio Chissini de Castro <helio.chissini.de.castro@cariad.technology>
1 parent bb4f333 commit 19a3ec3

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)