Skip to content

fix: skip special files instead of failing to compress - #1072

Open
jadhavgaurav wants to merge 1 commit into
ouch-org:mainfrom
jadhavgaurav:fix/skip-special-files-when-compressing
Open

jadhavgaurav wants to merge 1 commit into
ouch-org:mainfrom
jadhavgaurav:fix/skip-special-files-when-compressing

Conversation

@jadhavgaurav

Copy link
Copy Markdown

Problem

Compressing a directory that holds a socket or a fifo does not produce an archive.

$ ouch compress app out.tar.zst
[INFO] Compressing "app"
[INFO] Compressing "app/daphne.sock"
[ERROR] unsupported file type socket
 - found at "app/daphne.sock"

Same for .zip, and for .7z it fails later with failed to open file ... Operation not supported on socket (os error 102). tar skips these files and writes the archive, which
is what the issue asks for.

A fifo is worse: Handle::from_path opens the path to compare it with the output file, and
opening a fifo blocks until a writer shows up, so ouch compress dir_with_a_fifo out.tar
hangs forever with no output. I hit this while testing the socket fix.

Change

  • read_file_type returns Ok(None) for special files (sockets, fifos, block and character
    devices) instead of an error. Only the two archive builders called it.
  • The tar and zip builders skip those entries with a warning, and the 7z builder does the
    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.
$ ouch compress app out.tar.zst
[INFO] Compressing "app"
[WARNING] Skipping "app/daphne.sock", archives cannot store special files like sockets and fifos
[WARNING] Skipping "app/pipe", archives cannot store special files like sockets and fifos
[INFO] Compressing "app/regular.txt"
[INFO] Successfully compressed to "out.tar.zst"

Regular files, directories and symlinks are untouched.

Tests

New special_files_are_skipped_when_compressing in tests/integration.rs, unix only. It
puts 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 -- --check clean,
cargo clippy --all-targets -- -D warnings clean, cargo test green.

Fixes #851

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.
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.

Feature request: Ignore sockets (and maybe other special file types?)

1 participant