Compare commits
No commits in common. "4d553587aaf863c0dadbdf6c4667c9cd9937370f" and "2713083a8212dfc3a999096015627ed4b0bcc4d3" have entirely different histories.
4d553587aa
...
2713083a82
10 changed files with 39 additions and 73 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -2,16 +2,12 @@
|
|||
Dates are given in YYYY-MM-DD format.
|
||||
|
||||
## v0.2
|
||||
### v0.2.13 (2021-???)
|
||||
### v0.2.12 (2021-???)
|
||||
- Added Apple iWork document formats to documents extension set
|
||||
- Cleaned up and properly documented tests
|
||||
- Renamed `Script` (in `formats.rs`) to `Shell`, in line with renaming in `parameters.rs`
|
||||
- Added .rpa (Ren'Py archive) support to infer backend
|
||||
- Renamed `Script` (in `formats.rs`) to `Shell`, in line with renaming in `paramaters.rs`
|
||||
- Added .rpa (renpy archive) support
|
||||
- Added system extension set
|
||||
- [`xdg-mime`] no longer uses git version
|
||||
- Output is sorted: Files that couldn't be read, then files with no known mimetype, then files with no known extensions,
|
||||
then files with the wrong extension
|
||||
- Fixed some bad formatting in PowerShell output
|
||||
|
||||
### v0.2.12 (2021-04-14)
|
||||
#### Features
|
||||
|
|
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -202,7 +202,6 @@ dependencies = [
|
|||
"exitcode",
|
||||
"fastrand",
|
||||
"infer",
|
||||
"itertools",
|
||||
"log",
|
||||
"mime_guess",
|
||||
"once_cell",
|
||||
|
@ -283,15 +282,6 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
|
@ -752,8 +742,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
|||
[[package]]
|
||||
name = "xdg-mime"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87bf7b69bb50588d70a36e467be29d3df3e8c32580276d62eded9738c1a797aa"
|
||||
source = "git+https://github.com/ebassi/xdg-mime-rs?rev=de5a6dd#de5a6dd04b1a225894c51b5c6e5f5a22ffa46373"
|
||||
dependencies = [
|
||||
"dirs-next",
|
||||
"glob",
|
||||
|
|
10
Cargo.toml
10
Cargo.toml
|
@ -33,15 +33,16 @@ infer = "0.4.0"
|
|||
rayon = { version = "1.5.0", optional = true }
|
||||
exitcode = "1.1.2"
|
||||
cfg-if = "1.0.0"
|
||||
itertools = "0.10.0"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
xdg-mime = "0.3.3"
|
||||
xdg-mime = "0.3.2"
|
||||
|
||||
[target.'cfg(not(all(target_endian = "big", target_pointer_width = "32")))'.dependencies]
|
||||
smartstring = "0.2.6"
|
||||
|
||||
[patch.crates-io]
|
||||
# use git version while waiting on a release incorporating https://github.com/ebassi/xdg-mime-rs/commit/de5a6dd
|
||||
xdg-mime = { git = "https://github.com/ebassi/xdg-mime-rs", version = "0.3", rev = "de5a6dd" }
|
||||
# forked version with many more mime types
|
||||
mime_guess = { git = "https://github.com/Lynnesbian/mime_guess", version = "2.0.4" }
|
||||
|
||||
|
@ -69,9 +70,6 @@ lto = "thin"
|
|||
[profile.test]
|
||||
opt-level = 0
|
||||
|
||||
# optimise dependencies, even when producing debug and test builds
|
||||
# optimise dependencies, even when producing debug builds
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 3
|
||||
|
||||
[profile.test.package."*"]
|
||||
opt-level = 3
|
||||
|
|
|
@ -43,10 +43,9 @@ impl ExtensionSet {
|
|||
// many compressed file types follow the name scheme "application/x.+compressed.*" - maybe this can be used
|
||||
// somehow to extract extensions for compressed files from mime_guess?
|
||||
Self::Archives => vec!["zip", "tar", "gz", "zst", "xz", "rar", "7z", "bz", "bz2", "tgz", "rpa"],
|
||||
Self::System => vec![
|
||||
"com", "dll", "exe", "sys", "reg", "nt", "cpl", "msi", "efi", "bio", "rcv", "mbr", "sbf", "grub", "ko",
|
||||
"dylib", "pdb", "hdmp", "crash",
|
||||
Self::System => vec!["com", "dll", "exe", "sys", "reg", "nt", "cpl", "msi", "efi", "bio", "rcv", "mbr", "sbf", "grub", "ko", "dylib", "pdb", "hdmp", "crash",
|
||||
],
|
||||
Self::Archives => vec!["zip", "tar", "gz", "zst", "xz", "rar", "7z", "bz", "bz2", "tgz"],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
use std::path::Path;
|
||||
|
||||
use crate::string_type::String;
|
||||
use mime_guess::Mime;
|
||||
|
||||
use crate::inspectors::mime_extension_lookup;
|
||||
use crate::string_type::String;
|
||||
|
||||
/// Information about a scanned file.
|
||||
#[derive(Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub struct Findings<'a> {
|
||||
/// The location of the scanned file.
|
||||
pub file: &'a Path,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! The various formats that [fif](crate) can output to.
|
||||
|
||||
use std::ffi::OsStr;
|
||||
use std::io::{self, Write};
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
|
@ -10,7 +9,7 @@ use snailquote::escape;
|
|||
|
||||
use crate::scan_error::ScanError;
|
||||
use crate::{Findings, BACKEND};
|
||||
use itertools::Itertools;
|
||||
use std::ffi::OsStr;
|
||||
|
||||
/// The current version of fif, as defined in Cargo.toml.
|
||||
const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
|
||||
|
@ -84,23 +83,18 @@ pub trait Format {
|
|||
// TODO: clean this up - it's kinda messy
|
||||
self.header(entries, f)?;
|
||||
|
||||
// output will be generated in the order:
|
||||
// - files that couldn't be read
|
||||
// - files with no known mime type
|
||||
// - files with no known extension
|
||||
// - files with a known extension
|
||||
// files that already have a correct extension won't be represented in the output.
|
||||
for entry in entries {
|
||||
match entry {
|
||||
Ok(finding) => {
|
||||
if let Some(ext) = finding.recommended_extension() {
|
||||
self.rename(f, finding.file, &finding.file.with_extension(ext.as_str()))?
|
||||
} else {
|
||||
self.no_known_extension(f, finding.file)?
|
||||
}
|
||||
}
|
||||
|
||||
// sort errors so unreadable files appear before files with unknown mimetypes - ScanError impls Ord such that
|
||||
// ScanError::File > ScanError::Mime
|
||||
let errors = entries.iter().filter_map(|e| e.as_ref().err()).sorted();
|
||||
// sort files so that files with no known extension come before those with known extensions - None > Some("jpg")
|
||||
let findings = entries
|
||||
.iter()
|
||||
.filter_map(|e| e.as_ref().ok())
|
||||
.sorted_by(|a, b| b.recommended_extension().cmp(&a.recommended_extension()).reverse());
|
||||
|
||||
for error in errors {
|
||||
Err(error) => {
|
||||
// something went wrong 0uo
|
||||
match error {
|
||||
// failed to read the file
|
||||
ScanError::File(path) => self.unreadable(f, path)?,
|
||||
|
@ -108,12 +102,6 @@ pub trait Format {
|
|||
ScanError::Mime(path) => self.unknown_type(f, path)?,
|
||||
}
|
||||
}
|
||||
|
||||
for finding in findings {
|
||||
if let Some(ext) = finding.recommended_extension() {
|
||||
self.rename(f, finding.file, &finding.file.with_extension(ext.as_str()))?
|
||||
} else {
|
||||
self.no_known_extension(f, finding.file)?
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,7 +214,7 @@ impl Format for PowerShell {
|
|||
fn unknown_type<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()> {
|
||||
smart_write(
|
||||
f,
|
||||
&["<# Failed to detect mime type for ".into(), path.into(), "#>".into(), Writable::Newline],
|
||||
&["<# Failed to detect mime type for ".into(), path.into(), "#>".into()],
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -91,6 +91,8 @@ cached! {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
match exts {
|
||||
Some(exts) => {
|
||||
let possible_exts: Vec<String> = exts.iter().map(|e| String::from(*e)).collect();
|
||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -17,14 +17,11 @@
|
|||
#![forbid(unsafe_code)]
|
||||
#![warn(trivial_casts, unused_lifetimes, unused_qualifications)]
|
||||
|
||||
use std::ffi::OsStr;
|
||||
use std::io::{stdout, BufWriter, Write};
|
||||
use std::io::{stdout, BufWriter};
|
||||
use std::path::Path;
|
||||
use std::process::exit;
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use clap::Clap;
|
||||
use env_logger::Env;
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use once_cell::sync::OnceCell;
|
||||
#[cfg(feature = "multi-threaded")]
|
||||
|
@ -36,6 +33,9 @@ use crate::formats::{Format, PowerShell, Shell};
|
|||
use crate::mime_db::MimeDb;
|
||||
use crate::parameters::{OutputFormat, ScanOpts};
|
||||
use crate::scan_error::ScanError;
|
||||
use env_logger::Env;
|
||||
use std::ffi::OsStr;
|
||||
use std::process::exit;
|
||||
|
||||
mod extension_set;
|
||||
mod findings;
|
||||
|
@ -143,11 +143,6 @@ fn main() {
|
|||
exit(exitcode::IOERR);
|
||||
}
|
||||
|
||||
if buffered_stdout.flush().is_err() {
|
||||
error!("Failed to flush stdout.");
|
||||
exit(exitcode::IOERR);
|
||||
}
|
||||
|
||||
debug!("Done");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::fmt::{Display, Formatter, Result};
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug, PartialEq, PartialOrd, Ord, Eq)]
|
||||
#[derive(Debug)]
|
||||
pub enum ScanError<'a> {
|
||||
/// Something went wrong while trying to read the given file.
|
||||
File(&'a Path),
|
||||
|
|
|
@ -192,7 +192,7 @@ fn argument_parsing() {
|
|||
ScanOpts {
|
||||
hidden: false,
|
||||
extensionless: false,
|
||||
follow_symlinks: true,
|
||||
follow_symlinks: true
|
||||
},
|
||||
"ScanOpts are incorrect"
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue