Compare commits
No commits in common. "6ba17d57df00b765236b3a509ee9f67cf8a683ce" and "5a34a8d791a30728fc68e08e4ba7bbebabae607c" have entirely different histories.
6ba17d57df
...
5a34a8d791
5 changed files with 18 additions and 16 deletions
|
|
@ -57,7 +57,10 @@ impl CacheFile {
|
|||
};
|
||||
|
||||
if args.should_hash() {
|
||||
fn check_hash(file: &impl FileTrait, bar: &ProgressBar) -> crate::Result<()> {
|
||||
fn check_hash<'a>(
|
||||
file: &'a impl FileTrait<'a>,
|
||||
bar: &ProgressBar,
|
||||
) -> crate::Result<()> {
|
||||
bar.set_message(format!("checking {:?}", file.get_name()));
|
||||
file.check_hash(|bytes| bar.inc(bytes))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,16 +121,15 @@ impl Error {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_mismatch<E, A>(&self, want_expected: E, want_actual: A) -> bool
|
||||
pub fn is_mismatch<E, A>(&self, has_expected: E, has_actual: A) -> bool
|
||||
where
|
||||
E: AsRef<str>,
|
||||
A: AsRef<str>,
|
||||
String: PartialEq<E> + PartialEq<A>,
|
||||
{
|
||||
matches!(
|
||||
self,
|
||||
Self::Mismatch { expected, actual }
|
||||
if expected == want_expected.as_ref()
|
||||
&& actual == want_actual.as_ref()
|
||||
if *expected == has_expected
|
||||
&& *actual == has_actual
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,8 +91,8 @@ impl Checked {
|
|||
}
|
||||
}
|
||||
|
||||
impl FileTrait for Checked {
|
||||
fn get_name(&self) -> &str {
|
||||
impl<'t> FileTrait<'t> for Checked {
|
||||
fn get_name(&'t self) -> &'t str {
|
||||
<Self as FileTrait>::extract_file_name(&self.path)
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ impl FileTrait for Checked {
|
|||
super::check_hash(
|
||||
&self.path,
|
||||
self.size,
|
||||
self.hash.as_deref(),
|
||||
self.hash.as_ref().map(String::as_str),
|
||||
on_progress,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ pub use uploading::Uploading;
|
|||
const HASH_CHUNK_SIZE: usize = 4 * 1024 * 1024;
|
||||
|
||||
/// compute hash for a file given its path.
|
||||
/// Hash function: `BLAKE2b`, 512 bit
|
||||
/// Hash function: BLAKE2b, 512 bit
|
||||
///
|
||||
/// # Params
|
||||
///
|
||||
|
|
@ -96,13 +96,13 @@ fn check_hash(
|
|||
}
|
||||
}
|
||||
|
||||
pub trait FileTrait {
|
||||
pub trait FileTrait<'t> {
|
||||
/// extract the filename part of a `Path` reference
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Expects `path::Path::file_name` and `ffi::OsStr::to_str` to succeed on the given path
|
||||
fn extract_file_name(p: &Path) -> &str {
|
||||
fn extract_file_name(p: &'t Path) -> &'t str {
|
||||
p.file_name()
|
||||
.and_then(OsStr::to_str)
|
||||
.expect("bad file name")
|
||||
|
|
@ -111,7 +111,7 @@ pub trait FileTrait {
|
|||
/// get a reference to the file's name
|
||||
///
|
||||
/// Uses `file::FileTrait::extract_file_name`, which may **panic**!
|
||||
fn get_name(&self) -> &str;
|
||||
fn get_name(&'t self) -> &'t str;
|
||||
|
||||
/// get the file's size
|
||||
fn get_size(&self) -> u64;
|
||||
|
|
|
|||
|
|
@ -94,8 +94,8 @@ impl Uploading {
|
|||
}
|
||||
}
|
||||
|
||||
impl FileTrait for Uploading {
|
||||
fn get_name(&self) -> &str {
|
||||
impl<'t> FileTrait<'t> for Uploading {
|
||||
fn get_name(&'t self) -> &'t str {
|
||||
<Self as FileTrait>::extract_file_name(&self.path)
|
||||
}
|
||||
|
||||
|
|
@ -107,7 +107,7 @@ impl FileTrait for Uploading {
|
|||
super::check_hash(
|
||||
&self.path,
|
||||
self.size,
|
||||
self.hash.as_deref(),
|
||||
self.hash.as_ref().map(String::as_str),
|
||||
on_progress,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue