mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07: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:
Generated
-1
@@ -2385,7 +2385,6 @@ dependencies = [
|
||||
"clap 3.0.10",
|
||||
"libc",
|
||||
"uucore",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user