From 80ed8d514a0ea869ae904335f31e3e7713dabf2a Mon Sep 17 00:00:00 2001 From: Elden <69537751+elde-n@users.noreply.github.com> Date: Sun, 29 Dec 2024 12:14:35 +0000 Subject: [PATCH] rm: Remove an unecessary open call (#7010) it was causing some sandbox issues and it seems that isn't necessary after all --- src/uu/rm/src/rm.rs | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index ad9c942a8..c52497df1 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -8,8 +8,7 @@ use clap::{builder::ValueParser, crate_version, parser::ValueSource, Arg, ArgAction, Command}; use std::collections::VecDeque; use std::ffi::{OsStr, OsString}; -use std::fs::{self, File, Metadata}; -use std::io::ErrorKind; +use std::fs::{self, Metadata}; use std::ops::BitOr; #[cfg(not(windows))] use std::os::unix::ffi::OsStrExt; @@ -526,26 +525,16 @@ fn prompt_file(path: &Path, options: &Options) -> bool { } } // File::open(path) doesn't open the file in write mode so we need to use file options to open it in also write mode to check if it can written too - match File::options().read(true).write(true).open(path) { - Ok(file) => { - let Ok(metadata) = file.metadata() else { - return true; - }; + let Ok(metadata) = fs::metadata(path) else { + return true; + }; - if options.interactive == InteractiveMode::Always && !metadata.permissions().readonly() - { - return if metadata.len() == 0 { - prompt_yes!("remove regular empty file {}?", path.quote()) - } else { - prompt_yes!("remove file {}?", path.quote()) - }; - } - } - Err(err) => { - if err.kind() != ErrorKind::PermissionDenied { - return true; - } - } + if options.interactive == InteractiveMode::Always && !metadata.permissions().readonly() { + return if metadata.len() == 0 { + prompt_yes!("remove regular empty file {}?", path.quote()) + } else { + prompt_yes!("remove file {}?", path.quote()) + }; } prompt_file_permission_readonly(path) }