test on alpine, clippy & rustfmt
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
e3af10cf5b
commit
87dab7284f
9 changed files with 28 additions and 21 deletions
|
@ -4,7 +4,11 @@ type: docker
|
|||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
- name: linux-gnu
|
||||
image: rust:latest
|
||||
commands:
|
||||
- cargo test -j3
|
||||
- name: linux-musl
|
||||
image: rust:alpine
|
||||
commands:
|
||||
- cargo test -j3
|
||||
|
|
|
@ -8,7 +8,7 @@ cargo clippy -- \
|
|||
-W clippy::cargo \
|
||||
-A clippy::unused_io_amount \
|
||||
-A clippy::redundant_closure_for_method_calls \
|
||||
-A clippy::shadow_unrelated \
|
||||
-A clippy::shadow_unrelated
|
||||
|
||||
# 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
|
||||
|
|
|
@ -19,7 +19,7 @@ pub enum 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> {
|
||||
match self {
|
||||
Self::Images => mime_guess::get_mime_extensions_str("image/*").unwrap().to_vec(),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use mime_guess::Mime;
|
||||
use smartstring::alias::*;
|
||||
use smartstring::alias::String;
|
||||
|
||||
use crate::inspectors::mime_extension_lookup;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use std::io::{self, Write};
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
use std::path::{Path};
|
||||
use std::path::Path;
|
||||
|
||||
use snailquote::escape;
|
||||
|
||||
|
|
|
@ -14,12 +14,12 @@ use crate::mime_db::MimeDb;
|
|||
|
||||
/// 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
|
||||
/// 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;
|
||||
|
||||
/// 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;
|
||||
|
||||
/// Tries to identify the mimetype of a file from a given path.
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -189,20 +189,20 @@ fn wanted_file(entry: &DirEntry, exts: &[&str], scan_opts: &ScanOpts) -> bool {
|
|||
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
|
||||
/// (eventually) in future return an OsStr instead.
|
||||
/// (eventually) in future return an `OsStr` instead.
|
||||
// TODO: ↑
|
||||
fn extension_from_path(path: &Path) -> Option<String> {
|
||||
path.extension(). // Get the path's extension
|
||||
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
|
||||
/// [ScanError::Mime] will be returned, meaning that the file was scanned successfully, but a mimetype could not be
|
||||
/// 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
|
||||
/// determined.
|
||||
fn scan_file(entry: &DirEntry) -> Result<Findings, ScanError> {
|
||||
// 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>> {
|
||||
cfg_if! {
|
||||
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.
|
||||
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 mut probably_fatal_error = false;
|
||||
let entries: Vec<DirEntry> = stepper
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use crate::extension_set::ExtensionSet;
|
||||
use clap::{Clap, AppSettings};
|
||||
use clap::{AppSettings, Clap};
|
||||
use smartstring::{LazyCompact, SmartString};
|
||||
|
||||
#[derive(Clap, PartialEq, Debug)]
|
||||
|
@ -66,7 +66,7 @@ pub struct ScanOpts {
|
|||
/// Whether hidden files and directories should be scanned.
|
||||
pub hidden: bool,
|
||||
/// Whether files without extensions should be scanned.
|
||||
pub extensionless: bool
|
||||
pub extensionless: bool,
|
||||
}
|
||||
|
||||
impl Parameters {
|
||||
|
@ -83,7 +83,10 @@ impl Parameters {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_scan_opts(&self) -> ScanOpts {
|
||||
ScanOpts { hidden: self.scan_hidden, extensionless: self.scan_extensionless }
|
||||
pub const fn get_scan_opts(&self) -> ScanOpts {
|
||||
ScanOpts {
|
||||
hidden: self.scan_hidden,
|
||||
extensionless: self.scan_extensionless,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,9 +95,9 @@ fn simple_directory() {
|
|||
drop(file);
|
||||
}
|
||||
|
||||
let scan_opts = ScanOpts{
|
||||
let scan_opts = ScanOpts {
|
||||
hidden: true,
|
||||
extensionless: false
|
||||
extensionless: false,
|
||||
};
|
||||
|
||||
let entries = scan_directory(
|
||||
|
|
Loading…
Reference in a new issue