From 7fdc75c9e96931eaf31ea31f77261929cd314bf7 Mon Sep 17 00:00:00 2001 From: Lynne Date: Sat, 20 Feb 2021 03:57:19 +1000 Subject: [PATCH] windows support! and other stuff --- .gitignore | 1 - Cargo.lock | 2 +- Cargo.toml | 2 +- Cross.toml | 2 ++ src/extensionset.rs | 4 +++- src/formats.rs | 5 ++--- src/main.rs | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 Cross.toml diff --git a/.gitignore b/.gitignore index 3a8a8fd..0e32b75 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,5 @@ /imgs fif_* /old -/awful *.sh cargo-timing*.html diff --git a/Cargo.lock b/Cargo.lock index 29e55af..9e470dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -169,7 +169,7 @@ dependencies = [ [[package]] name = "fif" -version = "0.2.1" +version = "0.2.2" dependencies = [ "cached", "clap", diff --git a/Cargo.toml b/Cargo.toml index 4782794..4486f17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "fif" description = "A command-line tool for detecting and optionally correcting files with incorrect extensions." -version = "0.2.1" +version = "0.2.2" authors = ["Lynnesbian "] edition = "2018" license = "GPL-3.0-or-later" diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 0000000..4ddcbea --- /dev/null +++ b/Cross.toml @@ -0,0 +1,2 @@ +[build.env] +passthrough = ["RUST_BACKTRACE", "RUST_LOG"] \ No newline at end of file diff --git a/src/extensionset.rs b/src/extensionset.rs index c8bf4ba..644b69e 100644 --- a/src/extensionset.rs +++ b/src/extensionset.rs @@ -18,7 +18,9 @@ impl ExtensionSet { Self::Videos => vec!["webm", "mp4", "mkv", "mov", "avi", "m4v", "wmv", "bik", "ogv", "qt", "3gp", "3g2", "divx"], Self::Audio => vec!["ogg", "oga", "opus", "mp3", "m4a", "aac", "flac", "ape", "midi", "mid", "alac", "wav", "aiff", "aa3", "at3"], + Self::Documents => vec!["doc", "docx", "ppt", "pptx", "xls", "xlsx", "csv", "tsv", "pdf", "odt", "ods", "odp"], + Self::Archives => vec!["zip", "tar", "gz", "zst", "xz", "rar", "7z", "bz", "bz2"], _ => todo!() } } -} \ No newline at end of file +} diff --git a/src/formats.rs b/src/formats.rs index a391537..095b8ef 100644 --- a/src/formats.rs +++ b/src/formats.rs @@ -1,8 +1,6 @@ use std::io::{self, Write}; #[cfg(unix)] use std::os::unix::ffi::OsStrExt; -#[cfg(windows)] -use std::os::windows::ffi::OsStrExt; use std::path::PathBuf; use snailquote::escape; @@ -24,7 +22,8 @@ fn write_pathbuf(f: &mut W, path: &PathBuf) -> io::Result<()> { #[cfg(unix)] f.write_all(&*path.as_os_str().as_bytes())?; #[cfg(windows)] - f.write_all(&*path.as_os_str().encode_wide().collect())?; // TODO: TEST THIS + write!(f, "{}", path.as_os_str().to_string_lossy())?; // TODO: implement bonked strings for windows + // f.write_all(&*path.as_os_str().encode_wide().collect::>())?; write!(f, "'") } } diff --git a/src/main.rs b/src/main.rs index 035ffa8..11f2f55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,7 +49,7 @@ static MIMEDB: OnceCell = OnceCell::new(); #[cfg(windows)] fn is_hidden(entry: &DirEntry) -> bool { use std::os::windows::prelude::*; - std::fs::metadata(entry) // try to get metadata for file + std::fs::metadata(entry.path()) // try to get metadata for file .map_or( false, // if getting metadata/attributes fails, assume it's not hidden |f| f.file_attributes() & 0x2 > 0, // flag for hidden - https://docs.microsoft.com/windows/win32/fileio/file-attribute-constants