mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
rm: added new InteractiveMode InteractiveMode::Never
Signed-off-by: Stefin <stefin@pm.me>
This commit is contained in:
parent
9ffb00cd51
commit
a8326d7f3f
1 changed files with 7 additions and 3 deletions
|
@ -29,6 +29,7 @@ enum InteractiveMode {
|
||||||
Never,
|
Never,
|
||||||
Once,
|
Once,
|
||||||
Always,
|
Always,
|
||||||
|
Default,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
|
@ -114,7 +115,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
InteractiveMode::Never
|
InteractiveMode::Default
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
one_fs: matches.contains_id(OPT_ONE_FILE_SYSTEM),
|
one_fs: matches.contains_id(OPT_ONE_FILE_SYSTEM),
|
||||||
|
@ -386,7 +387,7 @@ fn remove_file(path: &Path, options: &Options) -> bool {
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
};
|
};
|
||||||
if response && prompt_write_protected(path, false) {
|
if response && prompt_write_protected(path, false, options) {
|
||||||
match fs::remove_file(path) {
|
match fs::remove_file(path) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
if options.verbose {
|
if options.verbose {
|
||||||
|
@ -408,7 +409,10 @@ fn remove_file(path: &Path, options: &Options) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prompt_write_protected(path: &Path, is_dir: bool) -> bool {
|
fn prompt_write_protected(path: &Path, is_dir: bool, options: &Options) -> bool {
|
||||||
|
if options.interactive == InteractiveMode::Never {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
match File::open(path) {
|
match File::open(path) {
|
||||||
Ok(_) => true,
|
Ok(_) => true,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue