Repository navigation
Commit d07bc3e
committed
Don't follow symlinks in append_dir_all() if follow_symlinks(false)
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)1 parent 2f9cfc2 commit d07bc3e
1 file changed
Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
870 | 870 | | |
871 | 871 | | |
872 | 872 | | |
873 | | - | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
874 | 885 | | |
875 | 886 | | |
876 | 887 | | |
| |||
0 commit comments