Skip to content

gh-161088: Make the gzip CLI replace its output file like gzip(1) - #161089

Merged
gpshead merged 2 commits into
python:mainfrom
gpshead:gzip-cli-output-symlink
Nov 1, 2026
Merged

gpshead merged 2 commits into
python:mainfrom
gpshead:gzip-cli-output-symlink

Conversation

@gpshead

@gpshead gpshead commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Like gzip -f, the CLI now unlinks an existing file at the output name and creates the output with O_EXCL and the input file's st_mode & 0o777 (subject to the umask), for both compression and decompression of file arguments; stdin/stdout use is unchanged. This keeps the existing "overwrite the old output" behaviour while no longer writing through a symlink, hardlink or fifo at that name. As a consequence a read-only input now gives a read-only output, and a directory the user cannot write to now fails instead of writing into an existing file there, so this is for main only. Only run on Linux: on Windows, removing a read-only existing output file would fail with PermissionError, which is untested.

Fixes #161088

ANT-2026-00DXM84J ANT-2026-746G5PBP

Remove an existing file at the output name and create the output with
O_EXCL and the input file's permission bits, so a symbolic link there is
no longer followed.
@read-the-docs-community

read-the-docs-community Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35563327 | 📁 Comparing 39c4c29 against main (b71fadc)

  🔍 Preview build  

2 files changed
± library/gzip.html
± whatsnew/changelog.html

@gpshead
gpshead marked this pull request as ready for review November 1, 2026 18:31
@gpshead
gpshead enabled auto-merge (squash) November 1, 2026 18:32
@gpshead
gpshead merged commit ed9cb4b into python:main Nov 1, 2026
55 checks passed
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.

python -m gzip writes through a symlink at the output name and ignores the input mode

1 participant