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/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 8ae8585f6..d3c04da47 100644 --- a/src/meta/windows_utils.rs +++ b/src/meta/windows_utils.rs @@ -13,7 +13,7 @@ use super::{Owner, Permissions}; const BUF_SIZE: u32 = 256; -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 @@ -168,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