replaced some pathbufs with paths, made it actually compile and work 0uo
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
6d55b3c309
commit
e3af10cf5b
6 changed files with 39 additions and 24 deletions
|
@ -10,6 +10,13 @@
|
||||||
</Attribute>
|
</Attribute>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry key="/src/formats.rs">
|
||||||
|
<value>
|
||||||
|
<Attribute>
|
||||||
|
<option name="separator" value="	" />
|
||||||
|
</Attribute>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
<entry key="/src/inspectors.rs">
|
<entry key="/src/inspectors.rs">
|
||||||
<value>
|
<value>
|
||||||
<Attribute>
|
<Attribute>
|
||||||
|
@ -38,6 +45,13 @@
|
||||||
</Attribute>
|
</Attribute>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry key="/src/tests/mod.rs">
|
||||||
|
<value>
|
||||||
|
<Attribute>
|
||||||
|
<option name="separator" value="	" />
|
||||||
|
</Attribute>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
</map>
|
</map>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use mime_guess::Mime;
|
use mime_guess::Mime;
|
||||||
|
use smartstring::alias::*;
|
||||||
|
|
||||||
use crate::inspectors::mime_extension_lookup;
|
use crate::inspectors::mime_extension_lookup;
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ pub struct Findings {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Findings {
|
impl Findings {
|
||||||
pub fn recommended_extension(&self) -> Option<&str> {
|
pub fn recommended_extension(&self) -> Option<String> {
|
||||||
mime_extension_lookup(self.mime.clone()).map(|extensions| &*extensions[0])
|
mime_extension_lookup(self.mime.clone()).map(|extensions| extensions[0].to_owned())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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::PathBuf;
|
use std::path::{Path};
|
||||||
|
|
||||||
use snailquote::escape;
|
use snailquote::escape;
|
||||||
|
|
||||||
|
@ -14,11 +14,11 @@ use crate::{Findings, BACKEND};
|
||||||
const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
|
const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
type Entries = [Result<Findings, ScanError>];
|
type Entries<'a> = [Result<Findings, ScanError<'a>>];
|
||||||
|
|
||||||
enum Writable<'a> {
|
enum Writable<'a> {
|
||||||
String(&'a str),
|
String(&'a str),
|
||||||
Path(&'a PathBuf),
|
Path(&'a Path),
|
||||||
Space,
|
Space,
|
||||||
Newline,
|
Newline,
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ impl<'a> From<&'a str> for Writable<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a PathBuf> for Writable<'a> {
|
impl<'a> From<&'a Path> for Writable<'a> {
|
||||||
fn from(p: &'a PathBuf) -> Writable<'a> {
|
fn from(p: &'a Path) -> Writable<'a> {
|
||||||
Writable::Path(p)
|
Writable::Path(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,10 +63,10 @@ fn smart_write<W: Write>(f: &mut W, writeables: &[Writable]) -> io::Result<()> {
|
||||||
|
|
||||||
pub trait Format {
|
pub trait Format {
|
||||||
fn new() -> Self;
|
fn new() -> Self;
|
||||||
fn rename<W: Write>(&self, f: &mut W, from: &PathBuf, to: &PathBuf) -> io::Result<()>;
|
fn rename<W: Write>(&self, f: &mut W, from: &Path, to: &Path) -> io::Result<()>;
|
||||||
fn no_known_extension<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()>;
|
fn no_known_extension<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()>;
|
||||||
fn unreadable<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()>;
|
fn unreadable<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()>;
|
||||||
fn unknown_type<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()>;
|
fn unknown_type<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()>;
|
||||||
fn header<W: Write>(&self, entries: &Entries, f: &mut W) -> io::Result<()>;
|
fn header<W: Write>(&self, entries: &Entries, f: &mut W) -> io::Result<()>;
|
||||||
fn footer<W: Write>(&self, entries: &Entries, f: &mut W) -> io::Result<()>;
|
fn footer<W: Write>(&self, entries: &Entries, f: &mut W) -> io::Result<()>;
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ impl Format for Script {
|
||||||
Self {}
|
Self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rename<W: Write>(&self, f: &mut W, from: &PathBuf, to: &PathBuf) -> io::Result<()> {
|
fn rename<W: Write>(&self, f: &mut W, from: &Path, to: &Path) -> io::Result<()> {
|
||||||
smart_write(
|
smart_write(
|
||||||
f,
|
f,
|
||||||
&[
|
&[
|
||||||
|
@ -122,18 +122,18 @@ impl Format for Script {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn no_known_extension<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()> {
|
fn no_known_extension<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()> {
|
||||||
smart_write(
|
smart_write(
|
||||||
f,
|
f,
|
||||||
&["echo No known extension for ".into(), path.into(), Writable::Newline],
|
&["echo No known extension for ".into(), path.into(), Writable::Newline],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unreadable<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()> {
|
fn unreadable<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()> {
|
||||||
smart_write(f, &["# Failed to read ".into(), path.into(), Writable::Newline])
|
smart_write(f, &["# Failed to read ".into(), path.into(), Writable::Newline])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unknown_type<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()> {
|
fn unknown_type<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()> {
|
||||||
smart_write(
|
smart_write(
|
||||||
f,
|
f,
|
||||||
&[
|
&[
|
||||||
|
|
|
@ -211,14 +211,14 @@ fn scan_file(entry: &DirEntry) -> Result<Findings, ScanError> {
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
// an error occurred while trying to read the file
|
// an error occurred while trying to read the file
|
||||||
// error!("{}: {}", entry.path().to_string_lossy(), error);
|
// error!("{}: {}", entry.path().to_string_lossy(), error);
|
||||||
return Err(ScanError::File(entry.path().to_path_buf()));
|
return Err(ScanError::File(entry.path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = result.unwrap();
|
let result = result.unwrap();
|
||||||
if result.is_none() {
|
if result.is_none() {
|
||||||
// the file was read successfully, but we were unable to determine its mimetype
|
// the file was read successfully, but we were unable to determine its mimetype
|
||||||
// warn!("Couldn't determine mimetype for {}", entry.path().to_string_lossy());
|
// warn!("Couldn't determine mimetype for {}", entry.path().to_string_lossy());
|
||||||
return Err(ScanError::Mime(entry.path().to_path_buf()));
|
return Err(ScanError::Mime(entry.path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = result.unwrap();
|
let result = result.unwrap();
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
use std::fmt::{Display, Formatter, Result};
|
use std::fmt::{Display, Formatter, Result};
|
||||||
use std::path::PathBuf;
|
use std::path::Path;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ScanError {
|
pub enum ScanError<'a> {
|
||||||
/// Something went wrong while trying to read the given file.
|
/// Something went wrong while trying to read the given file.
|
||||||
File(PathBuf),
|
File(&'a Path),
|
||||||
/// Failed to determine the mimetype of the given file.
|
/// Failed to determine the mimetype of the given file.
|
||||||
Mime(PathBuf),
|
Mime(&'a Path),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for ScanError {
|
impl<'a> Display for ScanError<'a> {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -125,14 +125,14 @@ fn simple_directory() {
|
||||||
// 3. ensure recommended extension is in the list of known extensions for PNG files
|
// 3. ensure recommended extension is in the list of known extensions for PNG files
|
||||||
assert!(mime_extension_lookup(IMAGE_PNG)
|
assert!(mime_extension_lookup(IMAGE_PNG)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.contains(&result.recommended_extension().unwrap()));
|
.contains(&result.recommended_extension().unwrap().into()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the recommended extension for this file is in the list of known extensions for its mimetype
|
// check if the recommended extension for this file is in the list of known extensions for its mimetype
|
||||||
assert!(mime_extension_lookup(result.mime.clone())
|
assert!(mime_extension_lookup(result.mime.clone())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.contains(&result.recommended_extension().unwrap()));
|
.contains(&result.recommended_extension().unwrap().into()));
|
||||||
|
|
||||||
// make sure the guessed mimetype is correct based on the extension of the scanned file
|
// make sure the guessed mimetype is correct based on the extension of the scanned file
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Reference in a new issue