test on alpine, clippy & rustfmt
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Lynne Megido 2021-03-12 03:44:31 +10:00
parent e3af10cf5b
commit 87dab7284f
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
9 changed files with 28 additions and 21 deletions

View file

@ -4,7 +4,11 @@ type: docker
name: default name: default
steps: steps:
- name: build - name: linux-gnu
image: rust:latest image: rust:latest
commands: commands:
- cargo test -j3 - cargo test -j3
- name: linux-musl
image: rust:alpine
commands:
- cargo test -j3

View file

@ -8,7 +8,7 @@ cargo clippy -- \
-W clippy::cargo \ -W clippy::cargo \
-A clippy::unused_io_amount \ -A clippy::unused_io_amount \
-A clippy::redundant_closure_for_method_calls \ -A clippy::redundant_closure_for_method_calls \
-A clippy::shadow_unrelated \ -A clippy::shadow_unrelated
# ALLOWS: # ALLOWS:
# unused_io_amount: there are two places where i want to read up to X bytes and i'm fine with getting less than that # unused_io_amount: there are two places where i want to read up to X bytes and i'm fine with getting less than that

View file

@ -19,7 +19,7 @@ pub enum ExtensionSet {
} }
impl ExtensionSet { impl ExtensionSet {
/// The list of known extensions for this ExtensionSet. /// The list of known extensions for this `ExtensionSet`.
pub fn extensions(&self) -> Vec<&str> { pub fn extensions(&self) -> Vec<&str> {
match self { match self {
Self::Images => mime_guess::get_mime_extensions_str("image/*").unwrap().to_vec(), Self::Images => mime_guess::get_mime_extensions_str("image/*").unwrap().to_vec(),

View file

@ -1,7 +1,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use mime_guess::Mime; use mime_guess::Mime;
use smartstring::alias::*; use smartstring::alias::String;
use crate::inspectors::mime_extension_lookup; use crate::inspectors::mime_extension_lookup;

View file

@ -3,7 +3,7 @@
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;
use std::path::{Path}; use std::path::Path;
use snailquote::escape; use snailquote::escape;

View file

@ -14,12 +14,12 @@ use crate::mime_db::MimeDb;
/// The number of bytes to read initially. /// The number of bytes to read initially.
/// ///
/// Rather than reading the entire file all at once into a [BUF_SIZE] buffer, it tends to be faster to read a small /// Rather than reading the entire file all at once into a [`BUF_SIZE`] buffer, it tends to be faster to read a small
/// chunk of the file and trying to identify that, proceeding with the larger buffer if that fails. Many file formats /// chunk of the file and trying to identify that, proceeding with the larger buffer if that fails. Many file formats
/// can be identified with the first few dozen bytes, so the "happy path" will likely be taken in the majority of cases. /// can be identified with the first few dozen bytes, so the "happy path" will likely be taken in the majority of cases.
const INITIAL_BUF_SIZE: usize = 128; const INITIAL_BUF_SIZE: usize = 128;
/// The number of bytes to read if the file couldn't be identified from its first [INITIAL_BUF_SIZE] bytes. /// The number of bytes to read if the file couldn't be identified from its first [`INITIAL_BUF_SIZE`] bytes.
const BUF_SIZE: usize = 4096; const BUF_SIZE: usize = 4096;
/// Tries to identify the mimetype of a file from a given path. /// Tries to identify the mimetype of a file from a given path.

View file

@ -189,20 +189,20 @@ fn wanted_file(entry: &DirEntry, exts: &[&str], scan_opts: &ScanOpts) -> bool {
exts.contains(&ext.unwrap().to_lowercase().as_str()) exts.contains(&ext.unwrap().to_lowercase().as_str())
} }
/// Given a file path, returns its extension, using [std::path::Path::extension]. /// Given a file path, returns its extension, using [`std::path::Path::extension`].
/// ///
/// The extension is currently [converted to a lossy string](std::ffi::OsStr::to_string_lossy), although it will /// The extension is currently [converted to a lossy string](std::ffi::OsStr::to_string_lossy), although it will
/// (eventually) in future return an OsStr instead. /// (eventually) in future return an `OsStr` instead.
// TODO: ↑ // TODO: ↑
fn extension_from_path(path: &Path) -> Option<String> { fn extension_from_path(path: &Path) -> Option<String> {
path.extension(). // Get the path's extension path.extension(). // Get the path's extension
map(|e| String::from(e.to_string_lossy())) // Convert from OsStr to String map(|e| String::from(e.to_string_lossy())) // Convert from OsStr to String
} }
/// Inspects the given entry, returning a [Findings] on success and a [ScanError] on failure. /// 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 /// In the event of an IO error, the returned [`ScanError`] will be of type [`ScanError::File`]. Otherwise, a
/// [ScanError::Mime] will be returned, meaning that the file was scanned successfully, but a mimetype could not be /// [`ScanError::Mime`] will be returned, meaning that the file was scanned successfully, but a mimetype could not be
/// determined. /// determined.
fn scan_file(entry: &DirEntry) -> Result<Findings, ScanError> { fn scan_file(entry: &DirEntry) -> Result<Findings, ScanError> {
// try to determine mimetype for this entry // try to determine mimetype for this entry
@ -242,7 +242,7 @@ fn scan_file(entry: &DirEntry) -> Result<Findings, ScanError> {
}) })
} }
/// Takes a slice of [DirEntry]s and calls [scan_file] on each one, returning the results in a vector. /// Takes a slice of [`DirEntry`]s and calls [`scan_file`] on each one, returning the results in a vector.
fn scan_from_walkdir(entries: &[DirEntry]) -> Vec<Result<Findings, ScanError>> { fn scan_from_walkdir(entries: &[DirEntry]) -> Vec<Result<Findings, ScanError>> {
cfg_if! { cfg_if! {
if #[cfg(feature = "multi-threaded")] { if #[cfg(feature = "multi-threaded")] {
@ -264,9 +264,9 @@ fn scan_from_walkdir(entries: &[DirEntry]) -> Vec<Result<Findings, ScanError>> {
} }
} }
/// Scans a given directory with [WalkDir], filters with [wanted_file], checks for errors, and returns a vector of /// Scans a given directory with [`WalkDir`], filters with [`wanted_file`], checks for errors, and returns a vector of
/// [DirEntry]s. /// [DirEntry]s.
fn scan_directory(dirs: &PathBuf, exts: &Vec<&str>, scan_opts: &ScanOpts) -> Option<Vec<DirEntry>> { fn scan_directory(dirs: &PathBuf, exts: &[&str], scan_opts: &ScanOpts) -> Option<Vec<DirEntry>> {
let stepper = WalkDir::new(dirs).into_iter(); let stepper = WalkDir::new(dirs).into_iter();
let mut probably_fatal_error = false; let mut probably_fatal_error = false;
let entries: Vec<DirEntry> = stepper let entries: Vec<DirEntry> = stepper

View file

@ -3,7 +3,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use crate::extension_set::ExtensionSet; use crate::extension_set::ExtensionSet;
use clap::{Clap, AppSettings}; use clap::{AppSettings, Clap};
use smartstring::{LazyCompact, SmartString}; use smartstring::{LazyCompact, SmartString};
#[derive(Clap, PartialEq, Debug)] #[derive(Clap, PartialEq, Debug)]
@ -66,7 +66,7 @@ pub struct ScanOpts {
/// Whether hidden files and directories should be scanned. /// Whether hidden files and directories should be scanned.
pub hidden: bool, pub hidden: bool,
/// Whether files without extensions should be scanned. /// Whether files without extensions should be scanned.
pub extensionless: bool pub extensionless: bool,
} }
impl Parameters { impl Parameters {
@ -83,7 +83,10 @@ impl Parameters {
} }
} }
pub fn get_scan_opts(&self) -> ScanOpts { pub const fn get_scan_opts(&self) -> ScanOpts {
ScanOpts { hidden: self.scan_hidden, extensionless: self.scan_extensionless } ScanOpts {
hidden: self.scan_hidden,
extensionless: self.scan_extensionless,
}
} }
} }

View file

@ -97,7 +97,7 @@ fn simple_directory() {
let scan_opts = ScanOpts { let scan_opts = ScanOpts {
hidden: true, hidden: true,
extensionless: false extensionless: false,
}; };
let entries = scan_directory( let entries = scan_directory(