2020-02-14 09:12:49 +01:00
|
|
|
use crate::common::*;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub(crate) struct FileStatus {
|
2020-03-15 11:22:33 +01:00
|
|
|
path: FilePath,
|
|
|
|
error: Option<FileError>,
|
2020-02-14 09:12:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FileStatus {
|
|
|
|
pub(crate) fn status(
|
2020-03-15 11:22:33 +01:00
|
|
|
absolute: &Path,
|
|
|
|
path: FilePath,
|
|
|
|
length: Bytes,
|
|
|
|
md5: Option<Md5Digest>,
|
2020-02-14 09:12:49 +01:00
|
|
|
) -> Self {
|
2020-03-15 11:22:33 +01:00
|
|
|
let error = FileError::verify(absolute, length, md5).err();
|
2020-02-14 09:12:49 +01:00
|
|
|
|
2020-03-15 11:22:33 +01:00
|
|
|
FileStatus { path, error }
|
2020-02-14 09:12:49 +01:00
|
|
|
}
|
|
|
|
|
2020-03-15 11:22:33 +01:00
|
|
|
pub(crate) fn is_good(&self) -> bool {
|
|
|
|
self.error.is_none()
|
2020-02-14 09:12:49 +01:00
|
|
|
}
|
|
|
|
|
2020-03-16 07:02:26 +01:00
|
|
|
#[cfg(test)]
|
2020-03-15 11:22:33 +01:00
|
|
|
pub(crate) fn is_bad(&self) -> bool {
|
|
|
|
!self.is_good()
|
2020-02-14 09:12:49 +01:00
|
|
|
}
|
|
|
|
|
2020-03-15 11:22:33 +01:00
|
|
|
pub(crate) fn error(&self) -> Option<&FileError> {
|
|
|
|
self.error.as_ref()
|
2020-02-14 09:12:49 +01:00
|
|
|
}
|
|
|
|
|
2020-03-15 11:22:33 +01:00
|
|
|
pub(crate) fn path(&self) -> &FilePath {
|
|
|
|
&self.path
|
2020-02-14 09:12:49 +01:00
|
|
|
}
|
|
|
|
}
|