Skip to content

Commit 6d09dee

Browse files
Ensure that the cached file is not empty before using it
We've observed multiple cases where a zero-byte file is cached, leading to crashes with the error message: zipfile.BadZipFile: File is not a zip file I was not able to reproduce this issue reliably enough to identify the root cause. However, adding a check to ensure that the cached file is not empty before using it will mitigate the problem. Signed-off-by: Marcel Bochtler <[email protected]>
1 parent dcd3609 commit 6d09dee

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/python_inspector/utils_pypi.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,14 @@ async def get(
16941694
cached = os.path.join(self.directory, cache_key)
16951695
lock_file = f"{cached}.lockfile"
16961696

1697-
if force or not os.path.exists(cached):
1697+
cache_valid = os.path.exists(cached) and os.path.getsize(cached) > 0
1698+
1699+
if force or not cache_valid:
1700+
if not cache_valid and os.path.exists(cached):
1701+
if TRACE_DEEP:
1702+
print(f" FILE CACHE INVALID (empty file): {path_or_url}")
1703+
os.remove(cached)
1704+
16981705
if TRACE_DEEP:
16991706
print(f" FILE CACHE MISS: {path_or_url}")
17001707
content = await get_file_content(

0 commit comments

Comments
 (0)