From 9114691a35f44df273ad83c842fbdf944f990877 Mon Sep 17 00:00:00 2001 From: Bo Maryniuk Date: Wed, 1 Nov 2023 22:20:34 +0100 Subject: [PATCH] Detect potential junk, add more coloring --- src/scanner/dlst.rs | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/scanner/dlst.rs b/src/scanner/dlst.rs index dbe5cf1..7e161fd 100644 --- a/src/scanner/dlst.rs +++ b/src/scanner/dlst.rs @@ -10,6 +10,8 @@ use std::{ use bytesize::ByteSize; use colored::Colorize; +use crate::filters::defs::{self}; + /// ContentFormatter is a lister for finally gathered information, /// that needs to be displayed on the screen for the user for review pub struct ContentFormatter<'a> { @@ -27,7 +29,7 @@ impl<'a> ContentFormatter<'a> { let mut t_size: u64 = 0; for (pi, p) in self.fs_data.iter().enumerate() { t_size += p.metadata().unwrap().len(); - let (dname, fname) = self.dn(p); + let (dname, mut fname) = self.dn(p); if self.last_dir != dname { self.last_dir = dname.to_owned(); @@ -36,12 +38,8 @@ impl<'a> ContentFormatter<'a> { } let mut leaf = " ├─"; - if pi == d_len { + if pi == d_len || (pi < d_len && dname != self.fs_data[pi + 1].parent().unwrap().to_str().unwrap()) { leaf = " ╰─"; - } else if pi < d_len { - if dname != self.fs_data[pi + 1].parent().unwrap().to_str().unwrap().to_string() { - leaf = " ╰─"; - } } if p.is_symlink() { @@ -55,6 +53,12 @@ impl<'a> ContentFormatter<'a> { } else if p.metadata().unwrap().permissions().mode() & 0o111 != 0 { println!("{} {}", leaf.blue(), fname.bright_green().bold()); } else { + if fname.ends_with(".so") || fname.contains(".so.") { + fname = fname.green().to_string(); + } else if self.is_potential_junk(&fname) { + fname = format!("{} {}", "⚠️".bright_red().bold(), fname.bright_red()); + } + println!("{} {}", leaf.blue(), fname); } } @@ -62,6 +66,29 @@ impl<'a> ContentFormatter<'a> { println!("\nPreserved {} files, taking space: {}\n", d_len + 1, ByteSize::b(t_size)); } + fn is_potential_junk(&self, fname: &str) -> bool { + for ext in + defs::DOC_F_EXT.iter().chain(defs::ARC_F_EXT.iter()).chain(defs::H_SRC_F_EXT.iter()).chain(defs::DOC_FP_EXT.iter()) + { + if fname.ends_with(ext) { + return true; + } + } + + for sf in defs::DOC_STUB_FILES { + if fname == *sf { + return true; + } + } + + // Potentially doc stubfile that doesn't look like a known one + if fname == fname.to_uppercase() { + return true; + } + + false + } + /// Get dir/name split, painted accordingly fn dn(&mut self, p: &Path) -> (String, String) { let dname = p.parent().unwrap().to_str().unwrap().to_string();