Skip to content

Commit

Permalink
Merge pull request #14 from isbm/isbm-cleanup-filters
Browse files Browse the repository at this point in the history
Update extensions and replace hardcoded values
  • Loading branch information
isbm authored Nov 2, 2023
2 parents 8e8c0f7 + 9455e78 commit f78d245
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
20 changes: 17 additions & 3 deletions src/filters/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,31 @@ pub const DOC_STUB_FILES: &[&str] =
&["AUTHORS", "COPYING", "LICENSE", "DEBUG", "DISTRIB", "DOC", "HISTORY", "README", "TERMS", "TODO"];

/// Docfiles
pub const DOC_F_EXT: &[&str] = &[".txt", ".doc", ".rtf", ".md", ".rtx", ".tex", ".xml"];
pub const DOC_F_EXT: &[&str] = &[".txt", ".doc", ".rtf", ".md", ".rtx", ".tex", ".xml", ".htm", ".html", ".log"];

/// Docfiles portable
pub const DOC_FP_EXT: &[&str] = &[".eps", ".pdf", ".ps"];

/// Typically, docs
pub const DOC_LOCATIONS: &[&str] = &["/usr/share/doc"];

/// Headers
pub const H_SRC_F_EXT: &[&str] = &[".h", ".hpp"];

/// Archives
pub const ARC_F_EXT: &[&str] = &[".gz", ".bz2", ".xz", ".zip", ".tar"];

/// Graphic files
pub const IMG_F_EXT: &[&str] =
&[".bmp", ".jpg", ".jpeg", ".png", ".gif", ".xpm", ".xbm", ".tif", ".tiff", ".pbm", ".svg", ".ico"];
pub const IMG_F_EXT: &[&str] = &[
".ani", ".bmp", ".dib", ".pcx", ".jpg", ".jpeg", ".jpx", ".jxr", ".png", ".gif", ".xpm", ".xbm", ".tif", ".tiff", ".iff",
".lbm", ".pbm", ".pgm", ".pict", ".svg", ".ico", ".ai",
];

/// Manpages
pub const D_MANPAGES: &str = "/usr/share/man";

/// Localisation
pub const D_L10N: &str = "/usr/share/locale";

/// Intetrnaetiomns... i18n
pub const D_I18N: &str = "/usr/share/i18n";
22 changes: 15 additions & 7 deletions src/filters/texts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::{
path::{Path, PathBuf},
};

use super::defs;

pub struct TextDataFilter {
data: HashSet<PathBuf>,
remove_manpages: bool,
Expand Down Expand Up @@ -45,7 +47,7 @@ impl TextDataFilter {
_p.pop();

self.remove_manpages
&& p.to_str().unwrap().starts_with("/usr/share/man")
&& p.to_str().unwrap().starts_with(defs::D_MANPAGES)
&& _p.file_name().unwrap().to_str().unwrap().starts_with("man")
}

Expand All @@ -55,21 +57,27 @@ impl TextDataFilter {
return false;
}

for c in defs::DOC_STUB_FILES {
if p.file_name().unwrap_or_default().to_str().unwrap_or_default().contains(c) {
return true;
}
}

let p = p.to_str().unwrap();

for c in ["/doc/", "changelog", "readme"] {
if p.to_lowercase().contains(c) {
for c in ["/doc/"].iter().chain(defs::DOC_STUB_FILES.iter()) {
if p.to_lowercase().contains(c.to_lowercase().as_str()) {
return true;
}
}

for c in ["/usr/share/doc"] {
for c in defs::DOC_LOCATIONS {
if p.starts_with(c) {
return true;
}
}

for c in [".txt", ".doc", ".md", ".rtx", ".htm", ".html"] {
for c in defs::DOC_F_EXT {
if p.ends_with(c) {
return true;
}
Expand All @@ -80,12 +88,12 @@ impl TextDataFilter {

/// Is localisation
fn filter_l10n(&self, p: &Path) -> bool {
self.remove_l10n && p.to_str().unwrap().starts_with("/usr/share/locale")
self.remove_l10n && p.to_str().unwrap().starts_with(defs::D_L10N)
}

/// Is internationalisation
fn filter_i18n(&self, p: &Path) -> bool {
self.remove_i18n && p.to_str().unwrap().starts_with("/usr/share/i18n")
self.remove_i18n && p.to_str().unwrap().starts_with(defs::D_I18N)
}
}

Expand Down

0 comments on commit f78d245

Please sign in to comment.