windows support! and other stuff

This commit is contained in:
Lynne Megido 2021-02-20 03:57:19 +10:00
parent dc2f642171
commit 7fdc75c9e9
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
7 changed files with 10 additions and 8 deletions

1
.gitignore vendored
View file

@ -2,6 +2,5 @@
/imgs /imgs
fif_* fif_*
/old /old
/awful
*.sh *.sh
cargo-timing*.html cargo-timing*.html

2
Cargo.lock generated
View file

@ -169,7 +169,7 @@ dependencies = [
[[package]] [[package]]
name = "fif" name = "fif"
version = "0.2.1" version = "0.2.2"
dependencies = [ dependencies = [
"cached", "cached",
"clap", "clap",

View file

@ -1,7 +1,7 @@
[package] [package]
name = "fif" name = "fif"
description = "A command-line tool for detecting and optionally correcting files with incorrect extensions." description = "A command-line tool for detecting and optionally correcting files with incorrect extensions."
version = "0.2.1" version = "0.2.2"
authors = ["Lynnesbian <lynne@bune.city>"] authors = ["Lynnesbian <lynne@bune.city>"]
edition = "2018" edition = "2018"
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"

2
Cross.toml Normal file
View file

@ -0,0 +1,2 @@
[build.env]
passthrough = ["RUST_BACKTRACE", "RUST_LOG"]

View file

@ -18,7 +18,9 @@ impl ExtensionSet {
Self::Videos => vec!["webm", "mp4", "mkv", "mov", "avi", "m4v", "wmv", "bik", "ogv", "qt", "3gp", "3g2", "divx"], 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", Self::Audio => vec!["ogg", "oga", "opus", "mp3", "m4a", "aac", "flac", "ape", "midi", "mid", "alac", "wav",
"aiff", "aa3", "at3"], "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!() _ => todo!()
} }
} }
} }

View file

@ -1,8 +1,6 @@
use std::io::{self, Write}; use std::io::{self, Write};
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::ffi::OsStrExt; use std::os::unix::ffi::OsStrExt;
#[cfg(windows)]
use std::os::windows::ffi::OsStrExt;
use std::path::PathBuf; use std::path::PathBuf;
use snailquote::escape; use snailquote::escape;
@ -24,7 +22,8 @@ fn write_pathbuf<W: Write>(f: &mut W, path: &PathBuf) -> io::Result<()> {
#[cfg(unix)] #[cfg(unix)]
f.write_all(&*path.as_os_str().as_bytes())?; f.write_all(&*path.as_os_str().as_bytes())?;
#[cfg(windows)] #[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::<Vec<u16>>())?;
write!(f, "'") write!(f, "'")
} }
} }

View file

@ -49,7 +49,7 @@ static MIMEDB: OnceCell<mimedb::XdgDb> = OnceCell::new();
#[cfg(windows)] #[cfg(windows)]
fn is_hidden(entry: &DirEntry) -> bool { fn is_hidden(entry: &DirEntry) -> bool {
use std::os::windows::prelude::*; 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( .map_or(
false, // if getting metadata/attributes fails, assume it's not hidden 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 |f| f.file_attributes() & 0x2 > 0, // flag for hidden - https://docs.microsoft.com/windows/win32/fileio/file-attribute-constants