Skip to content

Close ZipFile with context manager in unzip#2147

Merged
jensens merged 3 commits intocookiecutter:mainfrom
mohiuddin-khan-shiam:main
Nov 8, 2025
Merged

Close ZipFile with context manager in unzip#2147
jensens merged 3 commits intocookiecutter:mainfrom
mohiuddin-khan-shiam:main

Conversation

@mohiuddin-khan-shiam
Copy link
Copy Markdown
Contributor

The cookiecutter.zipfile.unzip() helper opened archives via ZipFile(zip_path) without closing them, leaving the file handle locked until garbage-collection.
On Windows this prevented cached .zip files from being deleted or overwritten and could exhaust file descriptors on all platforms.

This patch wraps the archive processing in:

with ZipFile(zip_path) as zip_file:

so the handle is deterministically released even when extraction errors (e.g., wrong password) occur. No behavioural changes beyond eliminating the resource leak.

@jensens jensens merged commit ff0c104 into cookiecutter:main Nov 8, 2025
7 checks passed
armandmasseaugit pushed a commit to armandmasseaugit/cookiecutter that referenced this pull request Nov 19, 2025
* Update zipfile.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jens W. Klein <jk@kleinundpartner.at>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants