Don't follow symlinks in append_dir_all() if follow_symlinks(false)#417
Open
nabijaczleweli wants to merge 2 commits into
Open
Don't follow symlinks in append_dir_all() if follow_symlinks(false)#417nabijaczleweli wants to merge 2 commits into
nabijaczleweli wants to merge 2 commits into
Conversation
Before (append_dir_all("file")):
called `Result::unwrap()` on an `Err` value: Os { code: 20, kind: NotADirectory, message: "Not a directory" }
called `Result::unwrap()` on an `Err` value: Os { code: 267, kind: NotADirectory, message: "The directory name is invalid." }
after (append_dir_all("file") or append_dir_all("symlink"):
called `Result::unwrap()` on an `Err` value: Custom { kind: NotADirectory, error: "append_dir_all() argument not a directory" }
Repro with
fn main() {
let mut tar = tar::Builder::new(std::io::stdout().lock());
tar.follow_symlinks(false);
tar.append_dir_all("", std::env::args_os().nth(1).unwrap()) .unwrap();
tar.finish().unwrap();
}
before:
$ ls -lnd src symlink Cargo.toml
-rw-r--r-- 1 1000 100 118 10-08 18:31 Cargo.toml
drwxr-xr-x 2 1000 100 60 10-08 17:57 src
lrwxrwxrwx 1 1000 100 3 10-08 18:30 symlink -> src
$ cargo run -- Cargo.toml | tar -tv
called `Result::unwrap()` on an `Err` value: Os { code: 20, kind: NotADirectory, message: "Not a directory" }
$ cargo run -- src | tar -tv
-rw-r--r-- 1000/100 211 2025-10-08 18:29 main.rs
$ cargo run -- symlink | tar -tv
-rw-r--r-- 1000/100 211 2025-10-08 18:29 main.rs
after:
$ cargo run -- Cargo.toml | tar -tv
called `Result::unwrap()` on an `Err` value: Custom { kind: NotADirectory, error: "append_dir_all() argument not a directory" }
$ cargo run -- src | tar -tv
-rw-r--r-- 1000/100 211 2025-10-08 18:29 main.rs
$ cargo run -- symlink | tar -tv
called `Result::unwrap()` on an `Err` value: Custom { kind: NotADirectory, error: "append_dir_all() argument not a directory" }
This also achieves parity with tar(1)
nabijaczleweli
added a commit
to thecoshman/http
that referenced
this pull request
Oct 8, 2025
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.
Before (append_dir_all("file")):
after (append_dir_all("file") or append_dir_all("symlink"):
Repro with
before:
after:
This also achieves parity with tar(1) which follow_symlinks() touts