From 75269103da1b0516c380425a015816a8527f2c4c Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Tue, 9 Feb 2021 14:42:10 -0800 Subject: [PATCH 1/3] Add fast-windows feature --- Cargo.toml | 1 + src/meta/windows_utils.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 526f6b874..160e59405 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,3 +56,4 @@ serial_test = "0.5" [features] sudo = [] +no-windows-permissions = [] diff --git a/src/meta/windows_utils.rs b/src/meta/windows_utils.rs index 8ae8585f6..b9e003e7e 100644 --- a/src/meta/windows_utils.rs +++ b/src/meta/windows_utils.rs @@ -13,6 +13,32 @@ use super::{Owner, Permissions}; const BUF_SIZE: u32 = 256; +#[cfg(feature = "no-windows-permissions")] +pub fn get_file_data(path: &Path) -> Result<(Owner, Permissions), io::Error> { + let owner = Owner::new("?".to_string(), "?".to_string()); + + let permissions = Permissions { + user_read: true, + user_write: true, + user_execute: true, + + group_read: true, + group_write: true, + group_execute: true, + + other_read: true, + other_write: true, + other_execute: true, + + sticky: false, + setuid: false, + setgid: false, + }; + + Ok((owner, permissions)) +} + +#[cfg(not(feature = "no-windows-permissions"))] pub fn get_file_data(path: &Path) -> Result<(Owner, Permissions), io::Error> { // Overall design: // This function allocates some data with GetNamedSecurityInfoW, From 4d3d5ebab904fa77b6e57fcf6aba6a1785973332 Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Fri, 12 Feb 2021 23:40:18 -0800 Subject: [PATCH 2/3] Set permissions values to false instead of true with `no-windows-permissions` feature --- src/meta/windows_utils.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/meta/windows_utils.rs b/src/meta/windows_utils.rs index b9e003e7e..0fce6c5d1 100644 --- a/src/meta/windows_utils.rs +++ b/src/meta/windows_utils.rs @@ -18,13 +18,13 @@ pub fn get_file_data(path: &Path) -> Result<(Owner, Permissions), io::Error> { let owner = Owner::new("?".to_string(), "?".to_string()); let permissions = Permissions { - user_read: true, - user_write: true, - user_execute: true, + user_read: false, + user_write: false, + user_execute: false, - group_read: true, - group_write: true, - group_execute: true, + group_read: false, + group_write: false, + group_execute: false, other_read: true, other_write: true, From 595c114a30c5eb6e723abe42cf773f8048dfb18b Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Mon, 22 Feb 2021 22:23:21 -0800 Subject: [PATCH 3/3] WIP --- src/meta/mod.rs | 15 ++++++++------- src/meta/owner.rs | 19 +++++++++++++++++-- src/meta/permissions.rs | 20 ++++++++++++++++++++ src/meta/windows_utils.rs | 30 ++---------------------------- 4 files changed, 47 insertions(+), 37 deletions(-) diff --git a/src/meta/mod.rs b/src/meta/mod.rs index d0c3f83aa..16f5bb7bb 100644 --- a/src/meta/mod.rs +++ b/src/meta/mod.rs @@ -212,14 +212,15 @@ impl Meta { }; #[cfg(unix)] - let owner = Owner::from(&metadata); - #[cfg(unix)] - let permissions = Permissions::from(&metadata); + let (owner, permissions) = (Some(Owner::from(&metadata)), Some(Permissions::from(&metadata))); + + #[cfg(all(windows, feature = "no-windows-permissions"))] + let (owner, permissions) = (None, None); - #[cfg(windows)] + #[cfg(all(windows, not(feature = "no-windows-permissions")))] let (owner, permissions) = windows_utils::get_file_data(&path)?; - let file_type = FileType::new(&metadata, symlink_meta.as_ref(), &permissions); + let file_type = FileType::new(&metadata, symlink_meta.as_ref(), &permissions.unwrap_or_default()); let name = Name::new(&path, file_type); let inode = INode::from(&metadata); let links = Links::from(&metadata); @@ -232,8 +233,8 @@ impl Meta { size: Size::from(&metadata), date: Date::from(&metadata), indicator: Indicator::from(file_type), - owner, - permissions, + owner: owner.unwrap_or_default(), + permissions: permissions.unwrap_or_default(), name, file_type, content: None, diff --git a/src/meta/owner.rs b/src/meta/owner.rs index a9ecd5c47..17b1e735d 100644 --- a/src/meta/owner.rs +++ b/src/meta/owner.rs @@ -15,6 +15,13 @@ impl Owner { } } +impl Default for Owner { + fn default() -> Owner + { + Owner { user: String::from(""), group: String::from("") } + } +} + #[cfg(unix)] impl<'a> From<&'a Metadata> for Owner { fn from(meta: &Metadata) -> Self { @@ -37,10 +44,18 @@ impl<'a> From<&'a Metadata> for Owner { impl Owner { pub fn render_user(&self, colors: &Colors) -> ColoredString { - colors.colorize(self.user.clone(), &Elem::User) + if self.user.len() == 0 { + colors.colorize("?".to_owned(), &Elem::User) + } else { + colors.colorize(self.user.clone(), &Elem::User) + } } pub fn render_group(&self, colors: &Colors) -> ColoredString { - colors.colorize(self.group.clone(), &Elem::Group) + if self.group.len() == 0 { + colors.colorize("?".to_owned(), &Elem::Group) + } else { + colors.colorize(self.group.clone(), &Elem::Group) + } } } diff --git a/src/meta/permissions.rs b/src/meta/permissions.rs index 4b3450a79..6169d16e7 100644 --- a/src/meta/permissions.rs +++ b/src/meta/permissions.rs @@ -103,6 +103,26 @@ impl Permissions { } } +impl Default for Permissions +{ + fn default() -> Permissions { + Permissions { + user_read: false, + user_write: false, + user_execute: false, + group_read: false, + group_write: false, + group_execute: false, + other_read: false, + other_write: false, + other_execute: false, + sticky: false, + setgid: false, + setuid: false + } + } +} + // More readable aliases for the permission bits exposed by libc. #[allow(trivial_numeric_casts)] #[cfg(unix)] diff --git a/src/meta/windows_utils.rs b/src/meta/windows_utils.rs index 0fce6c5d1..d3c04da47 100644 --- a/src/meta/windows_utils.rs +++ b/src/meta/windows_utils.rs @@ -13,33 +13,7 @@ use super::{Owner, Permissions}; const BUF_SIZE: u32 = 256; -#[cfg(feature = "no-windows-permissions")] -pub fn get_file_data(path: &Path) -> Result<(Owner, Permissions), io::Error> { - let owner = Owner::new("?".to_string(), "?".to_string()); - - let permissions = Permissions { - user_read: false, - user_write: false, - user_execute: false, - - group_read: false, - group_write: false, - group_execute: false, - - other_read: true, - other_write: true, - other_execute: true, - - sticky: false, - setuid: false, - setgid: false, - }; - - Ok((owner, permissions)) -} - -#[cfg(not(feature = "no-windows-permissions"))] -pub fn get_file_data(path: &Path) -> Result<(Owner, Permissions), io::Error> { +pub fn get_file_data(path: &Path) -> Result<(Option, Option), io::Error> { // Overall design: // This function allocates some data with GetNamedSecurityInfoW, // manipulates it only through WinAPI calls (treating the pointers as @@ -194,7 +168,7 @@ pub fn get_file_data(path: &Path) -> Result<(Owner, Permissions), io::Error> { winapi::um::winbase::LocalFree(sd_ptr); } - Ok((owner, permissions)) + Ok((Some(owner), Some(permissions))) } /// Evaluate an ACL for a particular trustee and get its access rights