diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/file_browser.rs | 14 | ||||
-rw-r--r-- | src/files.rs | 34 |
2 files changed, 44 insertions, 4 deletions
diff --git a/src/file_browser.rs b/src/file_browser.rs index ce4a843..bc01f37 100644 --- a/src/file_browser.rs +++ b/src/file_browser.rs @@ -19,6 +19,7 @@ use crate::fail::{HResult, HError, ErrorLog}; use crate::widget::{Events, WidgetCore}; use crate::proclist::ProcView; use crate::bookmarks::BMPopup; +use crate::term; use crate::term::ScreenExt; use crate::foldview::LogView; use crate::coordinates::Coordinates; @@ -271,9 +272,16 @@ impl FileBrowser { } pub fn main_widget_goto(&mut self, dir: &File) -> HResult<()> { - if dir.read_dir().is_err() { - self.show_status("Can't enter! Permission denied!").log(); - return Ok(()); + match dir.is_readable() { + Ok(true) => {}, + Ok(false) => { + let status = + format!("{}Stop right there, cowboy! Check your permisions!", + term::color_red()); + self.show_status(&status).log(); + return Ok(()); + } + err @ Err(_) => err.log() } let dir = dir.clone(); diff --git a/src/files.rs b/src/files.rs index 53f167a..2ea4512 100644 --- a/src/files.rs +++ b/src/files.rs @@ -9,7 +9,10 @@ use std::ffi::{OsStr, OsString}; use lscolors::LsColors; use mime_detective; -use users; +use users::{get_current_username, + get_current_groupname, + get_user_by_uid, + get_group_by_gid}; use chrono::TimeZone; use failure::Error; use notify::DebouncedEvent; @@ -553,6 +556,35 @@ impl File { Ok(()) } + pub fn is_readable(&self) -> HResult<bool> { + let meta = self.meta()?; + let current_user = get_current_username()?.to_string_lossy().to_string(); + let current_group = get_current_groupname()?.to_string_lossy().to_string(); + let file_user = get_user_by_uid(meta.uid())? + .name() + .to_string_lossy() + .to_string(); + let file_group = get_group_by_gid(meta.gid())? + .name() + .to_string_lossy() + .to_string(); + let perms = meta.mode(); + + let user_readable = perms & 0o400; + let group_readable = perms & 0o040; + let other_readable = perms & 0o004; + + if current_user == file_user && user_readable > 0 { + Ok(true) + } else if current_group == file_group && group_readable > 0 { + Ok(true) + } else if other_readable > 0 { + Ok(true) + } else { + Ok(false) + } + } + pub fn pretty_print_permissions(&self) -> HResult<String> { let perms: usize = format!("{:o}", self.meta()?.mode()).parse().unwrap(); let perms: usize = perms % 800; |