From 560a76d43fa44c4ebf9bdc51087647bb800bbe68 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 14 Jul 2019 17:42:06 +0800 Subject: Do not follow symbolic links when iterating directories! Fixes #24 --- src/interactive/app/handlers.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/interactive/app/handlers.rs b/src/interactive/app/handlers.rs index 0d6aa4e..efff7dc 100644 --- a/src/interactive/app/handlers.rs +++ b/src/interactive/app/handlers.rs @@ -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); @@ -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)); -- cgit v1.2.3