Skip to content

Commit

Permalink
Fix symlink traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Jan 2, 2024
1 parent ccac2b3 commit 4054779
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,15 @@ impl PathWrapper {
let is_directory = e
.file_type()
.ok()
.map(|file_type| file_type.is_dir())
.and_then(|file_type| {
// We need to use fs::metadata to resolve the actual path
// if it's a symlink.
if file_type.is_symlink() {
None
} else {
Some(file_type.is_dir())
}
})
.or_else(|| fs::metadata(&path).map(|m| m.is_dir()).ok())
.unwrap_or(false);
Self { path, is_directory }
Expand Down

0 comments on commit 4054779

Please sign in to comment.