fixed indentation, removed some unneeded clap features

This commit is contained in:
Lynne Megido 2021-02-12 01:43:47 +10:00
parent 82bdbebec5
commit 578f2f6be5
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
3 changed files with 35 additions and 41 deletions

9
Cargo.lock generated
View file

@ -94,7 +94,6 @@ dependencies = [
"indexmap", "indexmap",
"lazy_static", "lazy_static",
"os_str_bytes", "os_str_bytes",
"strsim 0.10.0",
"termcolor", "termcolor",
"terminal_size", "terminal_size",
"textwrap", "textwrap",
@ -187,7 +186,7 @@ dependencies = [
"ident_case", "ident_case",
"proc-macro2", "proc-macro2",
"quote", "quote",
"strsim 0.9.3", "strsim",
"syn", "syn",
] ]
@ -561,12 +560,6 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.60" version = "1.0.60"

View file

@ -23,7 +23,8 @@ snailquote = "0.3.0"
[dependencies.clap] [dependencies.clap]
version = "3.0.0-beta.2" version = "3.0.0-beta.2"
features = ["wrap_help"] default-features = false
features = ["wrap_help", "color", "derive", "std"]
[dependencies.env_logger] [dependencies.env_logger]
version = "0.8.2" version = "0.8.2"

View file

@ -28,10 +28,10 @@ use log::{debug, trace, info, warn};
use rayon::prelude::*; use rayon::prelude::*;
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use xdg_mime::SharedMimeInfo; use xdg_mime::SharedMimeInfo;
use std::io::stdout;
use crate::parameters::OutputFormat; use crate::parameters::OutputFormat;
use crate::scanerror::ScanError; use crate::scanerror::ScanError;
use crate::formats::{Script, Format}; use crate::formats::{Script, Format};
use std::io::stdout;
pub struct Findings { pub struct Findings {
file: PathBuf, file: PathBuf,
@ -102,43 +102,43 @@ fn extension_from_path(path: &Path) -> Option<String> {
} }
fn scan_file(db: &SharedMimeInfo, entry: &DirEntry) -> Result<Findings, (ScanError, PathBuf)> { fn scan_file(db: &SharedMimeInfo, entry: &DirEntry) -> Result<Findings, (ScanError, PathBuf)> {
// try to determine mimetype for this entry // try to determine mimetype for this entry
let result = inspectors::mime_type(db, entry.path()); let result = inspectors::mime_type(db, entry.path());
if result.is_err() { if result.is_err() {
// an error occurred while trying to read the file // an error occurred while trying to read the file
// error!("{}: {}", entry.path().to_string_lossy(), error); // error!("{}: {}", entry.path().to_string_lossy(), error);
return Err((ScanError::File, entry.path().to_path_buf())); return Err((ScanError::File, entry.path().to_path_buf()));
} }
let result = result.unwrap(); let result = result.unwrap();
if result.is_none() { if result.is_none() {
// the file was read successfully, but we were unable to determine its mimetype // the file was read successfully, but we were unable to determine its mimetype
// warn!("Couldn't determine mimetype for {}", entry.path().to_string_lossy()); // warn!("Couldn't determine mimetype for {}", entry.path().to_string_lossy());
return Err((ScanError::Mime, entry.path().to_path_buf())); return Err((ScanError::Mime, entry.path().to_path_buf()));
} }
let result = result.unwrap(); let result = result.unwrap();
// set of known extensions for the given mimetype // set of known extensions for the given mimetype
let known_exts = inspectors::mime_extension_lookup(result.clone()); let known_exts = inspectors::mime_extension_lookup(result.clone());
// file extension for this particular file // file extension for this particular file
let entry_ext = extension_from_path(entry.path()); let entry_ext = extension_from_path(entry.path());
let valid = match known_exts { let valid = match known_exts {
// there is a known set of extensions for this mimetype, and the file has an extension // there is a known set of extensions for this mimetype, and the file has an extension
Some(e) if entry_ext.is_some() => e.contains(&entry_ext.unwrap().to_lowercase().into()), Some(e) if entry_ext.is_some() => e.contains(&entry_ext.unwrap().to_lowercase().into()),
// there is a known set of extensions for this mimetype, but the file has no extension // there is a known set of extensions for this mimetype, but the file has no extension
Some(_) => false, Some(_) => false,
// there is no known set of extensions for this mimetype -- assume it's correct // there is no known set of extensions for this mimetype -- assume it's correct
None => true None => true
}; };
Ok(Findings { Ok(Findings {
file: entry.path().to_path_buf(), file: entry.path().to_path_buf(),
valid, // make this a function valid, // make this a function
mime: result, mime: result,
}) })
} }
fn scan_from_walkdir(db: &SharedMimeInfo, entries: Vec<DirEntry>) -> Vec<Result<Findings, (ScanError, PathBuf)>> { fn scan_from_walkdir(db: &SharedMimeInfo, entries: Vec<DirEntry>) -> Vec<Result<Findings, (ScanError, PathBuf)>> {