Skip to content

Commit

Permalink
rm: added new InteractiveMode InteractiveMode::Never
Browse files Browse the repository at this point in the history
Signed-off-by: Stefin <[email protected]>
  • Loading branch information
stefins committed Aug 23, 2022
1 parent 9ffb00c commit a8326d7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/uu/rm/src/rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum InteractiveMode {
Never,
Once,
Always,
Default,
}

struct Options {
Expand Down Expand Up @@ -114,7 +115,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
}
} else {
InteractiveMode::Never
InteractiveMode::Default
}
},
one_fs: matches.contains_id(OPT_ONE_FILE_SYSTEM),
Expand Down Expand Up @@ -386,7 +387,7 @@ fn remove_file(path: &Path, options: &Options) -> bool {
} else {
true
};
if response && prompt_write_protected(path, false) {
if response && prompt_write_protected(path, false, options) {
match fs::remove_file(path) {
Ok(_) => {
if options.verbose {
Expand All @@ -408,7 +409,10 @@ fn remove_file(path: &Path, options: &Options) -> bool {
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) {
Ok(_) => true,
Err(err) => {
Expand Down

0 comments on commit a8326d7

Please sign in to comment.