Compare commits
3 commits
0f9e414014
...
e834c3e7fa
Author | SHA1 | Date | |
---|---|---|---|
e834c3e7fa | |||
162ed80e1e | |||
fc45376673 |
11 changed files with 16 additions and 24 deletions
2
build.rs
2
build.rs
|
@ -1,5 +1,5 @@
|
||||||
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
//! File handling - scanning, detecting MIME types, and so on.
|
//! File handling - scanning, detecting MIME types, and so on.
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
//! The [`Findings`] and [`ScanError`] structs, used for conveying whether a given file was able to be scanned, whether
|
//! The [`Findings`] and [`ScanError`] structs, used for conveying whether a given file was able to be scanned, whether
|
||||||
//! its MIME type could be inferred, and whether the file should be renamed.
|
//! its MIME type could be inferred, and whether the file should be renamed.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
//! Logic for handling the various output formats that fif can output to.
|
//! Logic for handling the various output formats that fif can output to.
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
//! This library consists of all of the things fif needs to run. It only exists as a library to separate code, and to
|
//! This library consists of all of the things fif needs to run. It only exists as a library to separate code, and to
|
||||||
//! make documentation and testing a bit easier. I don't recommend using this as a library for your crate, as it may
|
//! make documentation and testing a bit easier. I don't recommend using this as a library for your crate, as it may
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// fif - a command-line tool for detecting and optionally correcting files with incorrect extensions.
|
// fif - a command-line tool for detecting and optionally correcting files with incorrect extensions.
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
//! Backend-neutral Mime database abstraction.
|
//! Backend-neutral Mime database abstraction.
|
||||||
|
|
||||||
|
@ -68,19 +68,16 @@ cfg_if! {
|
||||||
|
|
||||||
// Mach-O Binaries (The executable format used by macOS)
|
// Mach-O Binaries (The executable format used by macOS)
|
||||||
// my source for most of this info is this article: https://h3adsh0tzz.com/2020/01/macho-file-format/
|
// my source for most of this info is this article: https://h3adsh0tzz.com/2020/01/macho-file-format/
|
||||||
// like linux's ELF binaries, mach-o binaries do not typically have an extension, but if they did, it'd
|
|
||||||
// probably be something like ".macho", so, that'll do i guess. fif doesn't actually use the extensions
|
|
||||||
// specified here anyway.
|
|
||||||
info.add("application/x-mach-binary", "macho", |buf| {
|
info.add("application/x-mach-binary", "macho", |buf| {
|
||||||
// a 32-bit mach-o header occupies 28 bits of space, so any input smaller than that cannot be a mach-o
|
// a 32-bit mach-o header occupies 28 bits of space, so any input smaller than that cannot be a mach-o
|
||||||
// binary, even if it starts with the magic numbers.
|
// binary, even if it starts with the magic numbers.
|
||||||
// the three magic numbers that can appear are 0xFEEDFACF, 0xFEEDFACE, and 0xCAFEBABE. the code below
|
|
||||||
// checks for all three of these, in both big and little endian order.
|
|
||||||
|
|
||||||
// java class files also start with 0xCAFEBABE. since infer doesn't support detecting these files,
|
// java class files also start with 0xCAFEBABE. since infer doesn't support detecting these files,
|
||||||
// collisions are not an issue. if, however, infer does gain support for identifying java class files, the
|
// collisions are not an issue. if, however, infer does gain support for identifying java class files, the
|
||||||
// 0xCAFEBABE check should be removed, as java bytecode files are far more prevalent than 32-bit universal
|
// 0xCAFEBABE check should be removed, as java bytecode files are far more prevalent than 32-bit universal
|
||||||
// mach-o binaries [citation needed].
|
// mach-o binaries [citation needed].
|
||||||
|
|
||||||
|
// check for magic numbers (0xFEEDCACF, 0xFEEDFACE, 0xCAFEBABE) in both big and little endian forms
|
||||||
buf.len() >= 28 && [b"\xFE\xED\xFA\xCF", b"\xFE\xED\xFA\xCE", b"\xCA\xFE\xBA\xBE", b"\xCF\xFA\xED\xFE",
|
buf.len() >= 28 && [b"\xFE\xED\xFA\xCF", b"\xFE\xED\xFA\xCE", b"\xCA\xFE\xBA\xBE", b"\xCF\xFA\xED\xFE",
|
||||||
b"\xCE\xFA\xED\xFE", b"\xBE\xBA\xFE\xCA"].iter().any(|magic_numbers| buf.starts_with(&magic_numbers[..]))
|
b"\xCE\xFA\xED\xFE", b"\xBE\xBA\xFE\xCA"].iter().any(|magic_numbers| buf.starts_with(&magic_numbers[..]))
|
||||||
});
|
});
|
||||||
|
@ -94,8 +91,7 @@ cfg_if! {
|
||||||
// Scalable Vector Graphics
|
// Scalable Vector Graphics
|
||||||
info.add("image/svg+xml", "svg", |buf| {
|
info.add("image/svg+xml", "svg", |buf| {
|
||||||
// before doing the moderately expensive SVG check, we should make sure that the input is actually SGML-ish,
|
// before doing the moderately expensive SVG check, we should make sure that the input is actually SGML-ish,
|
||||||
// by which i mean, starts with anywhere from zero to ∞-1 whitespace characters, and then a less than sign,
|
// by which i mean, starts with the pattern "\s*<".
|
||||||
// and then there's some other stuff we don't care about right now
|
|
||||||
|
|
||||||
// so, here comes our fancy pants """""SGML-ish validator"""""
|
// so, here comes our fancy pants """""SGML-ish validator"""""
|
||||||
for c in buf {
|
for c in buf {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
//! Command line argument parsing logic and associated functions.
|
//! Command line argument parsing logic and associated functions.
|
||||||
|
|
||||||
|
@ -80,10 +80,8 @@ pub struct Parameters {
|
||||||
#[clap(long, requires = "fix")]
|
#[clap(long, requires = "fix")]
|
||||||
pub overwrite: bool,
|
pub overwrite: bool,
|
||||||
|
|
||||||
// NOTE: clap's comma-separated argument parser makes it impossible to specify extensions with commas in their name -
|
// NOTE: it is impossible (as far as i can tell) to accept extensions with commas in their name. i don't know why
|
||||||
// `-e sil\,ly` is treated as ["sil", "ly"] rather than as ["silly"], no matter how i escape the comma (in bash,
|
// you would ever want a file named something like "example.xy,z", though... fif's -e and -x flags don't support this.
|
||||||
// anyway). is this really an issue? it does technically exclude some perfectly valid extensions, but i've never seen
|
|
||||||
// a file extension with a comma in its name before.
|
|
||||||
/// Only examine files with these extensions.
|
/// Only examine files with these extensions.
|
||||||
/// Multiple extensions can be specified by either using the flag multiple times (`-e jpg -e png -e gif`), or by
|
/// Multiple extensions can be specified by either using the flag multiple times (`-e jpg -e png -e gif`), or by
|
||||||
/// separating them with commas (`-e jpg,png,gif`).
|
/// separating them with commas (`-e jpg,png,gif`).
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
|
@ -130,8 +130,6 @@ fn simple_directory() {
|
||||||
|
|
||||||
for (result, canonical_result) in results.iter().zip(canonical_results.iter()) {
|
for (result, canonical_result) in results.iter().zip(canonical_results.iter()) {
|
||||||
// there should be no IO errors during this test. any IO errors encountered are outside the scope of this test.
|
// there should be no IO errors during this test. any IO errors encountered are outside the scope of this test.
|
||||||
// let result = result.as_ref().expect("Error while scanning file");
|
|
||||||
// let canonical_result = canonical_result.as_ref().expect("Error while scanning file");
|
|
||||||
|
|
||||||
// paths should be canonical
|
// paths should be canonical
|
||||||
assert_eq!(canonicalize(&result.file).unwrap(), canonical_result.file);
|
assert_eq!(canonicalize(&result.file).unwrap(), canonical_result.file);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
//! Various minor utilities.
|
//! Various minor utilities.
|
||||||
|
|
||||||
|
|
2
test.py
2
test.py
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
# SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
# SPDX-FileCopyrightText: 2021-2022 Lynnesbian
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
Loading…
Reference in a new issue