Skip to content

Commit

Permalink
Do not follow symbolic links when iterating directories!
Browse files Browse the repository at this point in the history
Fixes #24
  • Loading branch information
Sebastian Thiel committed Jul 14, 2019
1 parent dd12ca7 commit 560a76d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/interactive/app/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ fn delete_directory_recursively(path: PathBuf) -> Result<(), usize> {
let mut dirs = Vec::new();
let mut num_errors = 0;
while let Some(path) = files_or_dirs.pop() {
let is_symlink = path
.metadata()
.map(|m| m.file_type().is_symlink())
.unwrap_or(false);
if is_symlink {
// do not follow symlinks
num_errors += into_error_count(fs::remove_file(&path));
continue;
}
match fs::read_dir(&path) {
Ok(iterator) => {
dirs.push(path);
Expand All @@ -310,11 +319,6 @@ fn delete_directory_recursively(path: PathBuf) -> Result<(), usize> {
}
}
}
Err(ref e) if e.kind() == io::ErrorKind::NotFound => {
// it could also be a broken symlink
num_errors += into_error_count(fs::remove_file(path));
continue;
}
Err(ref e) if e.kind() == io::ErrorKind::Other => {
// assume file, save IOps
num_errors += into_error_count(fs::remove_file(path));
Expand Down

0 comments on commit 560a76d

Please sign in to comment.