From 281ec190e0688b30619cb6d05c17426440ca10f4 Mon Sep 17 00:00:00 2001 From: xxyzz Date: Sat, 12 Feb 2022 20:10:17 +0800 Subject: [PATCH] chmod: replace walkdir with std::fs walkdir filters some files that need to be modified, for example, files inside an unreadable folder. --- Cargo.lock | 1 - src/uu/chmod/Cargo.toml | 1 - src/uu/chmod/src/chmod.rs | 16 +++++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 805c1c83a..fd036ac64 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2385,7 +2385,6 @@ dependencies = [ "clap 3.0.10", "libc", "uucore", - "walkdir", ] [[package]] diff --git a/src/uu/chmod/Cargo.toml b/src/uu/chmod/Cargo.toml index 237368cf4..07cf65d15 100644 --- a/src/uu/chmod/Cargo.toml +++ b/src/uu/chmod/Cargo.toml @@ -18,7 +18,6 @@ path = "src/chmod.rs" clap = { version = "3.0", features = ["wrap_help", "cargo"] } libc = "0.2.42" uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["fs", "mode"] } -walkdir = "2.2" [[bin]] name = "chmod" diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index 84c5850d6..19c4eced2 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -18,7 +18,6 @@ use uucore::libc::mode_t; #[cfg(not(windows))] use uucore::mode; use uucore::{format_usage, show_error, InvalidEncodingHandling}; -use walkdir::WalkDir; static ABOUT: &str = "Change the mode of each FILE to MODE. With --reference, change the mode of each FILE to that of RFILE."; @@ -227,10 +226,17 @@ impl Chmoder { if !self.recursive { r = self.chmod_file(file).and(r); } else { - for entry in WalkDir::new(&filename).into_iter().filter_map(|e| e.ok()) { - let file = entry.path(); - r = self.chmod_file(file).and(r); - } + r = self.walk_dir(file); + } + } + r + } + + fn walk_dir(&self, file_path: &Path) -> UResult<()> { + let mut r = self.chmod_file(file_path); + if file_path.is_dir() { + for dir_entry in fs::read_dir(file_path)? { + r = self.walk_dir(dir_entry?.path().as_path()); } } r