mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
rm: Remove an unecessary open call (#7010)
it was causing some sandbox issues and it seems that isn't necessary after all
This commit is contained in:
parent
746a17352d
commit
80ed8d514a
1 changed files with 10 additions and 21 deletions
|
@ -8,8 +8,7 @@
|
||||||
use clap::{builder::ValueParser, crate_version, parser::ValueSource, Arg, ArgAction, Command};
|
use clap::{builder::ValueParser, crate_version, parser::ValueSource, Arg, ArgAction, Command};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::ffi::{OsStr, OsString};
|
use std::ffi::{OsStr, OsString};
|
||||||
use std::fs::{self, File, Metadata};
|
use std::fs::{self, Metadata};
|
||||||
use std::io::ErrorKind;
|
|
||||||
use std::ops::BitOr;
|
use std::ops::BitOr;
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
@ -526,27 +525,17 @@ 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
|
// 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) {
|
let Ok(metadata) = fs::metadata(path) else {
|
||||||
Ok(file) => {
|
|
||||||
let Ok(metadata) = file.metadata() else {
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
if options.interactive == InteractiveMode::Always && !metadata.permissions().readonly()
|
if options.interactive == InteractiveMode::Always && !metadata.permissions().readonly() {
|
||||||
{
|
|
||||||
return if metadata.len() == 0 {
|
return if metadata.len() == 0 {
|
||||||
prompt_yes!("remove regular empty file {}?", path.quote())
|
prompt_yes!("remove regular empty file {}?", path.quote())
|
||||||
} else {
|
} else {
|
||||||
prompt_yes!("remove file {}?", path.quote())
|
prompt_yes!("remove file {}?", path.quote())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
if err.kind() != ErrorKind::PermissionDenied {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prompt_file_permission_readonly(path)
|
prompt_file_permission_readonly(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue