Skip to content

Commit

Permalink
filepreprocessor.rs improve filetype matching
Browse files Browse the repository at this point in the history
improve supplementary filetype matching in `path_to_filetype`
  • Loading branch information
jtmoon79 committed Aug 8, 2022
1 parent d5794c4 commit 48687e8
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/readers/filepreprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,44 @@ pub(crate) fn path_to_filetype(path: &Path) -> FileType {
dpxf!("return FileGz; .gzip");
return FileType::FileGz;
}
// for example, `media.gz`
// XXX: this should be handled in `path_to_filetype_mimeguess`
if file_suffix_s.ends_with("gz") {
dpxf!("return FileGz; .gz");
return FileType::FileGz;
}

// FileXz

// for example, `media.gz.old`
if file_name_s.ends_with(".xz.old") {
dpxf!("return FileXz; .xz.old");
return FileType::FileXz;
}
// for example, `media.gzip`
if file_suffix_s.ends_with("gzip") {
dpxf!("return FileXz; .xzip");
return FileType::FileXz;
}
// for example, `media.gz`
// XXX: this should be handled in `path_to_filetype_mimeguess`
if file_suffix_s.ends_with("xz") {
dpxf!("return FileXz; .xz");
return FileType::FileXz;
}

// FileTar

// for example, `var-log.tar.old`
// TODO: this should be handled in `path_to_filetype_mimeguess`, can be removed
if file_name_s.ends_with(".tar.old") {
dpxf!("return FileTar; .tar.old");
return FileType::FileTar;
}
// XXX: this should be handled in `path_to_filetype_mimeguess`
if file_name_s.ends_with(".tar") {
dpxf!("return FileTar; .tar");
return FileType::FileTar;
}

// other file patterns

Expand All @@ -256,6 +285,12 @@ pub(crate) fn path_to_filetype(path: &Path) -> FileType {
return FileType::File;
}

// for example, `dmesg.2`
if file_prefix_s == "dmesg" {
dpxf!("return File; dmesg");
return FileType::File;
}

dpxf!("return FileUnknown");

FileType::FileUnknown
Expand Down Expand Up @@ -481,6 +516,7 @@ pub fn process_path(path: &FPath) -> Vec<ProcessPathResult> {
return paths;
}
// is_archived
dpxf!("process_path_tar({:?})", path);
return process_path_tar(path);
}

Expand Down

0 comments on commit 48687e8

Please sign in to comment.