moved ScanError into findings.rs
This commit is contained in:
parent
0c0d3f12ea
commit
417893cae0
4 changed files with 29 additions and 31 deletions
|
@ -7,6 +7,7 @@ use crate::string_type::String;
|
||||||
|
|
||||||
#[cfg(feature = "json")]
|
#[cfg(feature = "json")]
|
||||||
use serde::{ser::SerializeStruct, Serializer};
|
use serde::{ser::SerializeStruct, Serializer};
|
||||||
|
use std::fmt::{Display, Formatter};
|
||||||
|
|
||||||
/// Information about a scanned file.
|
/// Information about a scanned file.
|
||||||
#[derive(Ord, PartialOrd, Eq, PartialEq)]
|
#[derive(Ord, PartialOrd, Eq, PartialEq)]
|
||||||
|
@ -40,3 +41,29 @@ impl<'a> Findings<'a> {
|
||||||
mime_extension_lookup(self.mime.clone()).map(|extensions| extensions[0].clone())
|
mime_extension_lookup(self.mime.clone()).map(|extensions| extensions[0].clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, PartialOrd, Ord, Eq)]
|
||||||
|
#[cfg_attr(feature = "json", derive(serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "json", serde(tag = "type", content = "path"))]
|
||||||
|
pub enum ScanError<'a> {
|
||||||
|
/// Something went wrong while trying to read the given file.
|
||||||
|
File(&'a Path),
|
||||||
|
/// Failed to determine the mimetype of the given file.
|
||||||
|
Mime(&'a Path),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Display for ScanError<'a> {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"Couldn't {} file: {}",
|
||||||
|
match self {
|
||||||
|
Self::File(_) => "read",
|
||||||
|
Self::Mime(_) => "determine mime type of",
|
||||||
|
},
|
||||||
|
match self {
|
||||||
|
Self::File(f) | Self::Mime(f) => f.to_string_lossy(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use std::path::Path;
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
use snailquote::escape;
|
use snailquote::escape;
|
||||||
|
|
||||||
use crate::scan_error::ScanError;
|
use crate::findings::ScanError;
|
||||||
use crate::{Findings, BACKEND};
|
use crate::{Findings, BACKEND};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ use crate::findings::Findings;
|
||||||
use crate::formats::{Format, PowerShell, Shell};
|
use crate::formats::{Format, PowerShell, Shell};
|
||||||
use crate::mime_db::MimeDb;
|
use crate::mime_db::MimeDb;
|
||||||
use crate::parameters::{OutputFormat, ScanOpts};
|
use crate::parameters::{OutputFormat, ScanOpts};
|
||||||
use crate::scan_error::ScanError;
|
use crate::findings::ScanError;
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
mod findings;
|
mod findings;
|
||||||
|
@ -41,7 +41,6 @@ mod formats;
|
||||||
mod inspectors;
|
mod inspectors;
|
||||||
mod mime_db;
|
mod mime_db;
|
||||||
mod parameters;
|
mod parameters;
|
||||||
mod scan_error;
|
|
||||||
pub(crate) mod string_type;
|
pub(crate) mod string_type;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, PartialOrd, Ord, Eq)]
|
|
||||||
#[cfg_attr(feature = "json", derive(serde::Serialize))]
|
|
||||||
#[cfg_attr(feature = "json", serde(tag = "type", content = "path"))]
|
|
||||||
pub enum ScanError<'a> {
|
|
||||||
/// Something went wrong while trying to read the given file.
|
|
||||||
File(&'a Path),
|
|
||||||
/// Failed to determine the mimetype of the given file.
|
|
||||||
Mime(&'a Path),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Display for ScanError<'a> {
|
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"Couldn't {} file: {}",
|
|
||||||
match self {
|
|
||||||
Self::File(_) => "read",
|
|
||||||
Self::Mime(_) => "determine mime type of",
|
|
||||||
},
|
|
||||||
match self {
|
|
||||||
Self::File(f) | Self::Mime(f) => f.to_string_lossy(),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue