moved ScanError into findings.rs

This commit is contained in:
Lynne Megido 2021-05-06 09:27:16 +10:00
parent 0c0d3f12ea
commit 417893cae0
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
4 changed files with 29 additions and 31 deletions

View file

@ -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(),
}
)
}
}

View file

@ -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;

View file

@ -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)]

View file

@ -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(),
}
)
}
}