Compare commits

...

3 Commits

Author SHA1 Message Date
Lynne Megido e834c3e7fa
Merge branch 'master' of https://gitlab.com/Lynnesbian/fif 2022-01-24 00:13:59 +10:00
Lynne Megido 162ed80e1e
remove/rewrite some particularly verbose comments 2022-01-23 03:18:25 +10:00
Lynne Megido fc45376673
updated copyright years, fixed reuse compliance
somehow i had listed the license as LGPL 3 instead of GPL 3 in all the reuse headers, and never noticed... 0uo
2022-01-23 03:10:17 +10:00
11 changed files with 16 additions and 24 deletions

View File

@ -1,5 +1,5 @@
// 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;

View File

@ -1,5 +1,5 @@
// 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.

View File

@ -1,5 +1,5 @@
// 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
//! its MIME type could be inferred, and whether the file should be renamed.

View File

@ -1,5 +1,5 @@
// 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.

View File

@ -1,5 +1,5 @@
// 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
//! make documentation and testing a bit easier. I don't recommend using this as a library for your crate, as it may

View File

@ -1,5 +1,5 @@
// 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.

View File

@ -1,5 +1,5 @@
// 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.
@ -68,19 +68,16 @@ cfg_if! {
// 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/
// 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| {
// 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.
// 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,
// 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
// 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",
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
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,
// by which i mean, starts with anywhere from zero to ∞-1 whitespace characters, and then a less than sign,
// and then there's some other stuff we don't care about right now
// by which i mean, starts with the pattern "\s*<".
// so, here comes our fancy pants """""SGML-ish validator"""""
for c in buf {

View File

@ -1,5 +1,5 @@
// 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.
@ -80,10 +80,8 @@ pub struct Parameters {
#[clap(long, requires = "fix")]
pub overwrite: bool,
// NOTE: clap's comma-separated argument parser makes it impossible to specify extensions with commas in their name -
// `-e sil\,ly` is treated as ["sil", "ly"] rather than as ["silly"], no matter how i escape the comma (in bash,
// 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.
// NOTE: it is impossible (as far as i can tell) to accept extensions with commas in their name. i don't know why
// you would ever want a file named something like "example.xy,z", though... fif's -e and -x flags don't support this.
/// 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
/// separating them with commas (`-e jpg,png,gif`).

View File

@ -1,5 +1,5 @@
// 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::ffi::OsStr;
@ -130,8 +130,6 @@ fn simple_directory() {
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.
// 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
assert_eq!(canonicalize(&result.file).unwrap(), canonical_result.file);

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2021-2022 Lynnesbian
// SPDX-License-Identifier: LGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later
//! Various minor utilities.

View File

@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: 2021-2022 Lynnesbian
#
# SPDX-License-Identifier: LGPL-3.0-or-later
# SPDX-License-Identifier: GPL-3.0-or-later
import re
import subprocess