alexcrichton / tar-rs

Tar file reading/writing for Rust
https://docs.rs/tar
Apache License 2.0
616 stars 178 forks source link

Confusing error with `append_path_with_name` and named pipes #356

Open Cerber-Ursi opened 3 months ago

Cerber-Ursi commented 3 months ago

Summary

When:

tar returns an error which doesn't seem to make any sense.

Reproduction

Checked on Linux, probably could be reproduced in a similar way on other Unix systems.

Setup

cargo new append_path_pipe_error
cd append_path_pipe_error
cargo add tar
mkfifo pipe
touch file

main.rs:

fn main() {
    let mut tar = tar::Builder::new(vec![]);
    let base_path = std::env::current_dir().unwrap();

    let mut append = move |name| {
        tar.append_path_with_name(base_path.join(name), name)
            .expect(name);
    };

    append("file"); // works
    append("pipe"); // breaks
}
cargo run

Expected

Either one of two:

Actual

Code returns the following error:

Custom { kind: Other, error: "paths in archives must be relative when setting path for " }

...which doesn't show the problematic path (it's empty when the error is generated) and names the problem that, from consumer's point of view, shouldn't arise at all (the in-archive path is relative, after all).

Possible reason

A little code-digging led me to this block, which calls append_special using only the source path, but ignoring the target one (i.e. name). I'm not sure whether this reasoning is correct and what could break if we simply replace path with name (hence an issue and not PR), but will be happy to help in testing if this is indeed the problem.