Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

append_dir_all fails on dangling symlinks #351

Open
larswirzenius opened this issue Dec 17, 2023 · 0 comments
Open

append_dir_all fails on dangling symlinks #351

larswirzenius opened this issue Dec 17, 2023 · 0 comments

Comments

@larswirzenius
Copy link

The following code creates a dangling symlink and tries to create a tar archive that includes the symlink. This fails with an error Error: No such file or directory (os error 2) on my Linux box.

fn main() -> anyhow::Result<()> {
    std::fs::create_dir("data")?;
    std::os::unix::fs::symlink("does-not-exist", "data/dangling")?;
    let f = std::fs::File::create("new.tar")?;
    let mut builder = tar::Builder::new(f);
    builder.append_dir_all(".", "data")?;
    builder.finish()?;
    Ok(())
}

I assume this is because follow defaults to true. Coming from a long-time Unix tar user, this surprises me. If I set follow to false, it still fails: Error: File exists (os error 17). This is also surprising.

Dangling symlinks are often an error, but they are technically valid in Unix, and can be used as an evil trick to store data that's not immediately obvious. I can understand if you don't want to support this, however. I'd be willing to try my hand at creating a patch to support this, however, if that would be welcome. I had a look and it wasn't immediately obvious to me how to make this change, though, so I though I'd start by reporting the issue.

@larswirzenius larswirzenius changed the title append_dir_all fails on danling symlinks append_dir_all fails on dangling symlinks Dec 23, 2023
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

No branches or pull requests

1 participant