From 2fa0f13db2a48dc869fc7429db2d2d5e780b6690 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Fri, 7 Jun 2024 21:49:20 +0200 Subject: [PATCH] builtins/path: Use fancy bitflags feature Just a cleanup TODO, no functional changes intended --- src/builtins/path.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/builtins/path.rs b/src/builtins/path.rs index efec75ad4..4e2fdd62b 100644 --- a/src/builtins/path.rs +++ b/src/builtins/path.rs @@ -86,7 +86,7 @@ impl TryFrom<&wstr> for TypeFlags { } bitflags! { - #[derive(Copy, Clone, Default)] + #[derive(Copy, Clone, Default, PartialEq)] pub struct PermFlags: u32 { const READ = 1 << 0; const WRITE = 1 << 1; @@ -405,7 +405,6 @@ fn path_transform( if transformed != arg { n_transformed += 1; // Return okay if path wasn't already in this form - // TODO: Is that correct? if opts.quiet { return STATUS_CMD_OK; }; @@ -798,26 +797,15 @@ fn filter_path(opts: &Options, path: &wstr, uid: Option, gid: Option) if let Some(perm) = opts.perms { let mut amode = 0; - // TODO: Update bitflags so this works - /* for f in perm { amode |= match f { PermFlags::READ => R_OK, PermFlags::WRITE => W_OK, PermFlags::EXEC => X_OK, - _ => PermFlags::empty(), + _ => 0, } } - */ - if perm.contains(PermFlags::READ) { - amode |= R_OK; - } - if perm.contains(PermFlags::WRITE) { - amode |= W_OK; - } - if perm.contains(PermFlags::EXEC) { - amode |= X_OK; - } + // access returns 0 on success, // -1 on failure. Yes, C can't even keep its bools straight. // Skip this if we don't have a mode to check - the stat can do existence too.