Skip to content

Make the isal.igzip command refuse to overwrite its input file - #323

Open
ptweezy wants to merge 2 commits into
pycompression:developfrom
ptweezy:cli-same-file
Open

ptweezy wants to merge 2 commits into
pycompression:developfrom
ptweezy:cli-same-file

Conversation

@ptweezy

@ptweezy ptweezy commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

python -m isal.igzip -f -o data data replaces data with an empty gzip file and exits with status 0. The input is also lost with -d, after answering y at the overwrite prompt, and when the output path names the input another way, such as ./data or a data.gz symlink to data. main() in src/isal/igzip.py opens the output with "wb", which truncates the input before it is read. The command now exits with an error before the overwrite prompt when os.path.samefile() reports that the input and output are the same file. The new test_infile_out_file_same_file test fails on develop.

Checklist

  • Pull request details were added to CHANGELOG.rst
  • Documentation was updated (if needed)

ptweezy and others added 2 commits November 5, 2026 17:22
main() opens the output with "wb" before it reads the input, which
truncates the input when both are the same file. With -f -o data data
the command replaced data with an empty gzip file and exited with
status 0.

@rhpvorderman rhpvorderman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, excellent. This will prevent some whoopsiedoodles.

This branch has not been deployed

No deployments
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