diff options
author | qkzk <qu3nt1n@gmail.com> | 2022-11-04 21:10:45 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2022-11-04 21:10:45 +0100 |
commit | af9bae95c598486b88feef3253d1e96e8cce2fbc (patch) | |
tree | 43ec8e44b7768030c8d03d0c0928c86f2ddbebf9 /src | |
parent | d558f46536b0a24d9037ad95a36ca8fdcaa9b7a6 (diff) |
Fix: prevent opening unknown extension & broken links to crash app.
Diffstat (limited to 'src')
-rw-r--r-- | src/fileinfo.rs | 17 | ||||
-rw-r--r-- | src/tab.rs | 11 |
2 files changed, 21 insertions, 7 deletions
diff --git a/src/fileinfo.rs b/src/fileinfo.rs index 650c369..0ddc4f9 100644 --- a/src/fileinfo.rs +++ b/src/fileinfo.rs @@ -120,7 +120,7 @@ impl FileKind { /// We read and keep tracks every displayable information about /// a file. /// Like in [exa](https://github.com/ogham/exa) we don't display the group. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct FileInfo { /// Full path of the file pub path: path::PathBuf, @@ -371,14 +371,21 @@ impl PathContent { } pub fn is_selected_dir(&self) -> FmResult<bool> { - if let FileKind::Directory = self + match self .selected_file() .ok_or_else(|| FmError::new("Empty directory"))? .file_kind { - Ok(true) - } else { - Ok(false) + FileKind::Directory => Ok(true), + FileKind::SymbolicLink => { + let dest = self + .selected_file() + .ok_or_else(|| FmError::new("unreachable"))? + .read_dest() + .unwrap_or_default(); + Ok(path::PathBuf::from(dest).is_dir()) + } + _ => Ok(false), } } @@ -381,13 +381,20 @@ impl Tab { } pub fn event_open_file(&mut self) -> FmResult<()> { - self.opener.open( + match self.opener.open( self.path_content .selected_file() .ok_or_else(|| FmError::new("Empty directory"))? .path .clone(), - )?; + ) { + Ok(_) => (), + Err(e) => eprint!( + "Error opening {:?}: {:?}", + self.path_content.selected_file(), + e + ), + } Ok(()) } |