fix: skip special files instead of failing to compress - #1072
Open
jadhavgaurav wants to merge 1 commit into
Open
jadhavgaurav wants to merge 1 commit into
jadhavgaurav wants to merge 1 commit into
Conversation
A socket or a fifo inside an input directory aborted the whole run, so no archive was written. tar skips those files and keeps going, do the same. read_file_type now reports special files as None rather than an error, and the tar, zip and 7z builders warn and skip them. The check runs before the output-file comparison, which opens the path, because opening a fifo blocks until a writer appears and hung compression forever.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Compressing a directory that holds a socket or a fifo does not produce an archive.
Same for
.zip, and for.7zit fails later withfailed to open file ... Operation not supported on socket (os error 102).tarskips these files and writes the archive, whichis what the issue asks for.
A fifo is worse:
Handle::from_pathopens the path to compare it with the output file, andopening a fifo blocks until a writer shows up, so
ouch compress dir_with_a_fifo out.tarhangs forever with no output. I hit this while testing the socket fix.
Change
read_file_typereturnsOk(None)for special files (sockets, fifos, block and characterdevices) instead of an error. Only the two archive builders called it.
same using the metadata it already reads. The check runs before the output-file
comparison, so nothing opens the path and the fifo case cannot block.
Regular files, directories and symlinks are untouched.
Tests
New
special_files_are_skipped_when_compressingintests/integration.rs, unix only. Itputs a regular file, a unix socket and a fifo in one directory, compresses it to tar, zip
and 7z, decompresses, and asserts the regular file is the only entry.
Checked against the unmodified sources with the test in place: it fails there (the socket
makes compression exit 1, the fifo hangs until the run is killed). With the change it
passes in under a second.
Local runs on the pinned 1.93.0 toolchain:
cargo +nightly fmt -- --checkclean,cargo clippy --all-targets -- -D warningsclean,cargo testgreen.Fixes #851