Skip to content

Commit 2a9f128

Browse files
Ensure that the cached file is not empty before using it (#251)
* Update expected test results Signed-off-by: Marcel Bochtler <marcel.bochtler@bosch.com> * 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 <marcel.bochtler@bosch.com> --------- Signed-off-by: Marcel Bochtler <marcel.bochtler@bosch.com>
1 parent dcd3609 commit 2a9f128

File tree

5 files changed

+45
-38
lines changed

5 files changed

+45
-38
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(

tests/data/azure-devops.req-310-expected.json

Lines changed: 9 additions & 9 deletions
Large diffs are not rendered by default.

tests/data/azure-devops.req-312-expected.json

Lines changed: 9 additions & 9 deletions
Large diffs are not rendered by default.

tests/data/azure-devops.req-313-expected.json

Lines changed: 9 additions & 9 deletions
Large diffs are not rendered by default.

tests/data/test-api-with-requirement-file.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3727,12 +3727,12 @@
37273727
"type": "pypi",
37283728
"namespace": null,
37293729
"name": "pip",
3730-
"version": "25.2",
3730+
"version": "25.3",
37313731
"qualifiers": {},
37323732
"subpath": null,
37333733
"primary_language": "Python",
37343734
"description": "The PyPA recommended tool for installing Python packages.\npip - The Python Package Installer\n==================================\n\n.. |pypi-version| image:: https://img.shields.io/pypi/v/pip.svg\n :target: https://pypi.org/project/pip/\n :alt: PyPI\n\n.. |python-versions| image:: https://img.shields.io/pypi/pyversions/pip\n :target: https://pypi.org/project/pip\n :alt: PyPI - Python Version\n\n.. |docs-badge| image:: https://readthedocs.org/projects/pip/badge/?version=latest\n :target: https://pip.pypa.io/en/latest\n :alt: Documentation\n\n|pypi-version| |python-versions| |docs-badge|\n\npip is the `package installer`_ for Python. You can use pip to install packages from the `Python Package Index`_ and other indexes.\n\nPlease take a look at our documentation for how to install and use pip:\n\n* `Installation`_\n* `Usage`_\n\nWe release updates regularly, with a new version every 3 months. Find more details in our documentation:\n\n* `Release notes`_\n* `Release process`_\n\nIf you find bugs, need help, or want to talk to the developers, please use our mailing lists or chat rooms:\n\n* `Issue tracking`_\n* `Discourse channel`_\n* `User IRC`_\n\nIf you want to get involved head over to GitHub to get the source code, look at our development documentation and feel free to jump on the developer mailing lists and chat rooms:\n\n* `GitHub page`_\n* `Development documentation`_\n* `Development IRC`_\n\nCode of Conduct\n---------------\n\nEveryone interacting in the pip project's codebases, issue trackers, chat\nrooms, and mailing lists is expected to follow the `PSF Code of Conduct`_.\n\n.. _package installer: https://packaging.python.org/guides/tool-recommendations/\n.. _Python Package Index: https://pypi.org\n.. _Installation: https://pip.pypa.io/en/stable/installation/\n.. _Usage: https://pip.pypa.io/en/stable/\n.. _Release notes: https://pip.pypa.io/en/stable/news.html\n.. _Release process: https://pip.pypa.io/en/latest/development/release-process/\n.. _GitHub page: https://github.com/pypa/pip\n.. _Development documentation: https://pip.pypa.io/en/latest/development\n.. _Issue tracking: https://github.com/pypa/pip/issues\n.. _Discourse channel: https://discuss.python.org/c/packaging\n.. _User IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa\n.. _Development IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa-dev\n.. _PSF Code of Conduct: https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md",
3735-
"release_date": "2025-07-30T21:50:13",
3735+
"release_date": "2025-10-25T00:55:39",
37363736
"parties": [
37373737
{
37383738
"type": "person",
@@ -3759,11 +3759,11 @@
37593759
"Topic :: Software Development :: Build Tools"
37603760
],
37613761
"homepage_url": null,
3762-
"download_url": "https://files.pythonhosted.org/packages/b7/3f/945ef7ab14dc4f9d7f40288d2df998d1837ee0888ec3659c813487572faa/pip-25.2-py3-none-any.whl",
3763-
"size": 1752557,
3762+
"download_url": "https://files.pythonhosted.org/packages/44/3c/d717024885424591d5376220b5e836c2d5293ce2011523c9de23ff7bf068/pip-25.3-py3-none-any.whl",
3763+
"size": 1778622,
37643764
"sha1": null,
3765-
"md5": "52af72c263169cc46cc32bed310a5eab",
3766-
"sha256": "6d67a2b4e7f14d8b31b8b52648866fa717f45a1eb70e83002f4331d07e953717",
3765+
"md5": "4bbbf9f0745c4117c8ecc77c561ef74b",
3766+
"sha256": "9655943313a94722b7774661c21049070f6bbb0a1516bf02f7c8d5d9201514cd",
37673767
"sha512": null,
37683768
"bug_tracking_url": null,
37693769
"code_view_url": "https://github.com/pypa/pip",
@@ -3778,9 +3778,9 @@
37783778
"dependencies": [],
37793779
"repository_homepage_url": null,
37803780
"repository_download_url": null,
3781-
"api_data_url": "https://pypi.org/pypi/pip/25.2/json",
3781+
"api_data_url": "https://pypi.org/pypi/pip/25.3/json",
37823782
"datasource_id": null,
3783-
"purl": "pkg:pypi/pip@25.2"
3783+
"purl": "pkg:pypi/pip@25.3"
37843784
},
37853785
{
37863786
"type": "pypi",
@@ -6158,13 +6158,13 @@
61586158
]
61596159
},
61606160
{
6161-
"package": "pkg:pypi/pip@25.2",
6161+
"package": "pkg:pypi/pip@25.3",
61626162
"dependencies": []
61636163
},
61646164
{
61656165
"package": "pkg:pypi/pipdeptree@2.2.1",
61666166
"dependencies": [
6167-
"pkg:pypi/pip@25.2"
6167+
"pkg:pypi/pip@25.3"
61686168
]
61696169
},
61706170
{

0 commit comments

Comments
 (0)