1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

chmod: replace walkdir with std::fs

walkdir filters some files that need to be modified, for example, files inside an unreadable folder.
This commit is contained in:
xxyzz 2022-02-12 20:10:17 +08:00
parent 19af43222b
commit 281ec190e0
No known key found for this signature in database
GPG key ID: F796163E6DCFEE9D
3 changed files with 11 additions and 7 deletions

1
Cargo.lock generated
View file

@ -2385,7 +2385,6 @@ dependencies = [
"clap 3.0.10",
"libc",
"uucore",
"walkdir",
]
[[package]]

View file

@ -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"

View file

@ -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