mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-05 15:37:47 +00:00
More readable unix write permissions for directory using libc
This commit is contained in:
parent
a3f35a726c
commit
fddc8c9d9d
2 changed files with 6 additions and 5 deletions
|
@ -20,6 +20,9 @@ walkdir = "2.2"
|
|||
remove_dir_all = "0.7.0"
|
||||
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["fs"] }
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
libc = "0.2.135"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winapi = { version="0.3", features=[] }
|
||||
|
||||
|
|
|
@ -557,8 +557,8 @@ fn prompt_file(path: &Path, options: &Options, is_dir: bool) -> bool {
|
|||
fn handle_writable_directory(path: &Path, options: &Options, metadata: &Metadata) -> bool {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let mode = metadata.permissions().mode();
|
||||
let user_write_permission = (mode & 0b1_1100_0000) >> 6;
|
||||
let user_writable = !matches!(user_write_permission, 0o0 | 0o1 | 0o4 | 0o5);
|
||||
// Check if directory has user write permissions
|
||||
let user_writable = (mode & libc::S_IWUSR) != 0;
|
||||
if !user_writable {
|
||||
prompt(&(format!("remove write-protected directory {}? ", path.quote())))
|
||||
} else if options.interactive == InteractiveMode::Always {
|
||||
|
@ -587,9 +587,7 @@ fn handle_writable_directory(path: &Path, options: &Options, metadata: &Metadata
|
|||
#[cfg(not(windows))]
|
||||
#[cfg(not(unix))]
|
||||
fn handle_writable_directory(path: &Path, options: &Options, metadata: &Metadata) -> bool {
|
||||
if metadata.permissions().readonly() {
|
||||
prompt(&(format!("remove write-protected directory {}? ", path.quote())))
|
||||
} else if options.interactive == InteractiveMode::Always {
|
||||
if options.interactive == InteractiveMode::Always {
|
||||
prompt(&(format!("remove directory {}? ", path.quote())))
|
||||
} else {
|
||||
true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue