a minor multitude of meager modifications

- clippy.sh now works if you're a weirdo with spaces in their $HOME path
- a """performance optimisation""" to utils.rs so minor that i would be surprised if it saved the world one microwatt of electricity over my entire lifespan
- cargo update
- removed useless extension_from_path function
This commit is contained in:
Lynne Megido 2021-07-31 23:33:18 +10:00
parent 8cdd0a8fc1
commit c3adaea88c
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90
6 changed files with 21 additions and 21 deletions

View File

@ -3,5 +3,8 @@
<option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="RegExpRepeatedSpace" enabled="true" level="INFORMATION" enabled_by_default="true" />
<inspection_tool class="ShellCheck" enabled="true" level="ERROR" enabled_by_default="true">
<shellcheck_settings value="SC2016" />
</inspection_tool>
</profile>
</component>

14
Cargo.lock generated
View File

@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "arrayvec"
version = "0.5.2"
@ -105,9 +107,9 @@ dependencies = [
[[package]]
name = "crossbeam-deque"
version = "0.8.0"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9"
checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e"
dependencies = [
"cfg-if",
"crossbeam-epoch",
@ -549,18 +551,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.126"
version = "1.0.127"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03"
checksum = "f03b9878abf6d14e6779d3f24f07b2cfa90352cfec4acc5aab8f1ac7f146fae8"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.126"
version = "1.0.127"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43"
checksum = "a024926d3432516606328597e0f224a51355a493b49fdd67e9209187cbe55ecc"
dependencies = [
"proc-macro2",
"quote",

View File

@ -1,6 +1,6 @@
#!/bin/bash
set -e
source $HOME/.cargo/env || true
source "$HOME"/.cargo/env || true
_extra=""
_ver=""

View File

@ -17,7 +17,6 @@
#![forbid(unsafe_code)]
#![warn(trivial_casts, unused_lifetimes, unused_qualifications)]
use std::ffi::OsStr;
use std::io::{stdout, BufWriter, Write};
use std::path::Path;
use std::process::exit;
@ -213,7 +212,7 @@ fn wanted_file(
return true;
}
if let Some(ext) = extension_from_path(entry.path()) {
if let Some(ext) = entry.path().extension() {
// file has extension - discard invalid UTF-8 and normalise it to lowercase.
let ext = ext.to_string_lossy().to_lowercase();
let ext = ext.as_str();
@ -231,9 +230,6 @@ fn wanted_file(
}
}
/// Given a file path, returns its extension, using [`std::path::Path::extension`].
fn extension_from_path(path: &Path) -> Option<&OsStr> { path.extension() }
/// Inspects the given entry, returning a [`Findings`] on success and a [`ScanError`] on failure.
///
/// In the event of an IO error, the returned [`ScanError`] will be of type [`ScanError::File`]. Otherwise, a
@ -254,7 +250,7 @@ fn scan_file(entry: &DirEntry, canonical_paths: bool) -> Result<Findings, ScanEr
// set of known extensions for the given mimetype
let known_exts = inspectors::mime_extension_lookup(result.essence_str().into());
// file extension for this particular file
let entry_ext = extension_from_path(path);
let entry_ext = path.extension();
let valid = match known_exts {
// there is a known set of extensions for this mimetype, and the file has an extension

View File

@ -3,7 +3,7 @@ use crate::formats::{Format, PowerShell, Shell};
use crate::inspectors::{mime_extension_lookup, BUF_SIZE};
use crate::mime_db::MimeDb;
use crate::string_type::String;
use crate::{extension_from_path, scan_directory, scan_from_walkdir};
use crate::{scan_directory, scan_from_walkdir};
use crate::parameters::Parameters;
use clap::Clap;
@ -49,7 +49,7 @@ fn get_ext() {
ext_checks.insert(Path::new(".hidden"), None);
for (path, ext) in ext_checks {
assert_eq!(extension_from_path(path), ext);
assert_eq!(path.extension(), ext);
}
}
@ -142,7 +142,7 @@ fn simple_directory() {
if !result.valid {
// the only invalid file detected should be "wrong.jpg", which is a misnamed png file
// 1. ensure detected extension is "jpg"
assert_eq!(extension_from_path(result.file.as_path()).unwrap(), OsStr::new("jpg"));
assert_eq!(result.file.as_path().extension().unwrap(), OsStr::new("jpg"));
// 2. ensure detected mime type is IMAGE_PNG
assert_eq!(result.mime, IMAGE_PNG);
// 3. ensure the recommended extension for "wrong.jpg" is "png"
@ -160,11 +160,10 @@ fn simple_directory() {
// make sure the guessed mimetype is correct based on the extension of the scanned file
// because we already know that the extensions match the mimetype (as we created these files ourselves earlier in
// the test), all files with the "jpg" extension should be IMAGE_JPEGs, etc.
let ext = extension_from_path(result.file.as_path());
assert!(ext.is_some());
let ext = result.file.as_path().extension().unwrap();
assert_eq!(
result.mime,
match ext.unwrap().to_string_lossy().borrow() {
match ext.to_string_lossy().borrow() {
"jpg" | "jpeg" => IMAGE_JPEG,
"png" => IMAGE_PNG,
"pdf" => APPLICATION_PDF,
@ -173,7 +172,7 @@ fn simple_directory() {
},
"Incorrect MIME type detected - got {:?} for a {:?} file",
result.mime,
ext.unwrap()
ext
);
}
}

View File

@ -23,7 +23,7 @@ static CLAP_LONG_VERSION: OnceCell<String> = OnceCell::new();
/// Sets [`CLAP_VERSION`] to be the version defined in Cargo.toml, prefixed with a v (e.g. "v0.3.1"), then returns it as
/// a String.
pub fn clap_version() -> &'static str { CLAP_VERSION.get_or_init(|| format!("v{}", VERSION.unwrap_or("???"))) }
pub fn clap_version() -> &'static str { CLAP_VERSION.get_or_init(|| String::from("v") + VERSION.unwrap_or("???")) }
/// Sets [`CLAP_LONG_VERSION`] to be similar to [`CLAP_VERSION`], followed by the chosen backend in parentheses (e.g.
/// "v0.3.1 (XDG-Mime backend)"), then returns it as a String.