diff options
author | qkzk <qu3nt1n@gmail.com> | 2024-03-02 18:13:21 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2024-03-02 18:19:32 +0100 |
commit | 715229c9e46bc28b39e9965c15760c5eddcf3a8c (patch) | |
tree | 55a2d2bdf3c60d01d4bced74d2fd2ef9b1427719 | |
parent | 6ab12b4b360a858d447487ef3f6b14f3d8888d94 (diff) |
replace `tar tvf` by `bsdtar -v --list --file`. Which can preview .deb and .rpm files
-rw-r--r-- | development.md | 3 | ||||
-rw-r--r-- | src/common/constant_strings_paths.rs | 4 | ||||
-rw-r--r-- | src/modes/display/preview.rs | 9 | ||||
-rw-r--r-- | src/modes/edit/decompress.rs | 7 |
4 files changed, 12 insertions, 11 deletions
diff --git a/development.md b/development.md index 6a4963b..e313b13 100644 --- a/development.md +++ b/development.md @@ -873,6 +873,7 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally. Watchout, if you try to open text & non text files at the same time, it will run a new terminal with your text editor instead. Don't mix file kinds. - Dynamic filtering while typing a filter - Search as you type: do / then type a pattern and you will jump to the match. +- replace `tar tvf` by `bsdtar -v --list --file`. Which can preview .deb and .rpm files #### Changelog @@ -942,11 +943,11 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally. - [x] FIX: leaving (with escape) should reset the filter, not leave - [x] setting a filter reset the "found" searched path & index - [x] search as you type +- [x] replace `tar tvf` by `bsdtar -v --list --file`. Which can preview .deb and .rpm files ## TODO - [ ] rclone -- [ ] temporary marks like normal but memory only - [ ] FIX: leaving flagged file should reset the window correctly. Can't reproduce... - [ ] use the new mpsc event parser to read commands from stdin or RPC - [ ] [opener file kind](./src/io/opener.rs): move associations to a config file diff --git a/src/common/constant_strings_paths.rs b/src/common/constant_strings_paths.rs index ffa9550..c8477d6 100644 --- a/src/common/constant_strings_paths.rs +++ b/src/common/constant_strings_paths.rs @@ -202,8 +202,8 @@ pub const GIO: &str = "gio"; pub const LSOF: &str = "lsof"; /// neovim executable pub const NVIM: &str = "nvim"; -/// tar executable -pub const TAR: &str = "tar"; +/// bsdtar executable, used to display archive content +pub const BSDTAR: &str = "bsdtar"; /// libreoffice executable pub const LIBREOFFICE: &str = "libreoffice"; /// lazygit diff --git a/src/modes/display/preview.rs b/src/modes/display/preview.rs index 0c91ced..a04e2a9 100644 --- a/src/modes/display/preview.rs +++ b/src/modes/display/preview.rs @@ -56,7 +56,7 @@ impl ExtensionKind { pub fn matcher(ext: &str) -> Self { match ext { "zip" | "gzip" | "bzip2" | "xz" | "lzip" | "lzma" | "tar" | "mtree" | "raw" | "7z" - | "gz" | "zst" => Self::Archive, + | "gz" | "zst" | "deb" | "rpm" => Self::Archive, "png" | "jpg" | "jpeg" | "tiff" | "heif" | "gif" | "cr2" | "nef" | "orf" | "sr2" => { Self::Image } @@ -615,9 +615,8 @@ impl BinaryContent { if nb_bytes_read != Self::LINE_WIDTH { content.push(Line::new((&buffer[0..nb_bytes_read]).into())); break; - } else { - content.push(Line::new(buffer.into())); } + content.push(Line::new(buffer.into())); if content.len() >= Self::SIZE_LIMIT { break; } @@ -719,7 +718,7 @@ impl ArchiveContent { fn new(path: &Path, ext: &str) -> Result<Self> { let content = match ext { "zip" => list_files_zip(path).unwrap_or(vec!["Invalid Zip content".to_owned()]), - "zst" | "gz" | "bz" | "xz" | "gzip" | "bzip2" => { + "zst" | "gz" | "bz" | "xz" | "gzip" | "bzip2" | "deb" | "rpm" => { list_files_tar(path).unwrap_or(vec!["Invalid Tar content".to_owned()]) } _ => vec![format!("Unsupported format: {ext}")], @@ -926,9 +925,7 @@ impl Ueberzug { surface.write_to_png(&mut file)?; surface.finish(); // those drops should be useless - drop(doc); drop(ctx); - drop(page); drop(surface); Ok(length) } diff --git a/src/modes/edit/decompress.rs b/src/modes/edit/decompress.rs index 0b91350..de853f6 100644 --- a/src/modes/edit/decompress.rs +++ b/src/modes/edit/decompress.rs @@ -4,7 +4,7 @@ use std::fs::File; use std::path::Path; use tar::Archive; -use crate::common::{path_to_string, TAR}; +use crate::common::{path_to_string, BSDTAR}; use crate::io::execute_and_output; /// Decompress a zipped compressed file into its parent directory. @@ -88,7 +88,10 @@ pub fn list_files_tar<P>(source: P) -> Result<Vec<String>> where P: AsRef<Path>, { - if let Ok(output) = execute_and_output(TAR, ["tvf", path_to_string(&source).as_str()]) { + if let Ok(output) = execute_and_output( + BSDTAR, + ["-v", "--list", "--file", path_to_string(&source).as_str()], + ) { let output = String::from_utf8(output.stdout).unwrap_or_default(); let content = output.lines().map(std::borrow::ToOwned::to_owned).collect(); return Ok(content); |