summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sthiel@thoughtworks.com>2019-07-14 17:42:06 +0800
committerSebastian Thiel <sthiel@thoughtworks.com>2019-07-14 17:42:06 +0800
commit560a76d43fa44c4ebf9bdc51087647bb800bbe68 (patch)
treefbb3ada1f5ef9f925a9164187d7c9c2d58f3396d
parentdd12ca765b7c7726e718b64035dedd0c9b3d50a0 (diff)
Do not follow symbolic links when iterating directories!
Fixes #24
-rw-r--r--src/interactive/app/handlers.rs14
1 files 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));