Skip to content

Commit 7958fd0

Browse files
committed
rm: fix prompt logic read-only files
1 parent 43bf7dc commit 7958fd0

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/uu/rm/src/rm.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -636,19 +636,15 @@ fn prompt_file(path: &Path, options: &Options) -> bool {
636636
prompt_yes!("remove file {}?", path.quote())
637637
};
638638
}
639-
let stdin_ok = options.__presume_input_tty.unwrap_or(false) || stdin().is_terminal();
640-
let prompt_protected = stdin_ok && options.interactive == InteractiveMode::PromptProtected;
641-
if prompt_protected || options.interactive == InteractiveMode::Always {
642-
prompt_file_permission_readonly(path)
643-
} else {
644-
true
645-
}
639+
prompt_file_permission_readonly(path, options)
646640
}
647641

648-
fn prompt_file_permission_readonly(path: &Path) -> bool {
649-
match fs::metadata(path) {
650-
Ok(_) if is_writable(path) => true,
651-
Ok(metadata) if metadata.len() == 0 => prompt_yes!(
642+
fn prompt_file_permission_readonly(path: &Path, options: &Options) -> bool {
643+
let stdin_ok = options.__presume_input_tty.unwrap_or(false) || stdin().is_terminal();
644+
match (stdin_ok, fs::metadata(path), options.interactive) {
645+
(false, _, InteractiveMode::PromptProtected) => true,
646+
(_, Ok(_), _) if is_writable(path) => true,
647+
(_, Ok(metadata), _) if metadata.len() == 0 => prompt_yes!(
652648
"remove write-protected regular empty file {}?",
653649
path.quote()
654650
),

0 commit comments

Comments
 (0)