diff --git a/cli/src/main.rs b/cli/src/main.rs index 6a33597..01d899f 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -206,14 +206,7 @@ fn main() -> Result<()> { } let entity = match entity { - entity if entity.starts_with('=') => { - let filepath = Path::new(&entity[1..]); - debug!("Hashing {:?}...", filepath); - let fbuffer = FileBuffer::open(&filepath)?; - let digest = hash(&fbuffer); - trace!("Finished hashing {:?}...", &filepath); - Address::Hash(digest).to_string() - } + entity if entity.starts_with('=') => hash_path(&entity[1..])?.to_string(), entity if entity.starts_with("http") => Address::Url(entity).to_string(), _ => entity, }; @@ -245,14 +238,7 @@ fn main() -> Result<()> { format, } => { let address = match _type { - AddressType::File => { - let filepath = PathBuf::from(input); - debug!("Hashing {:?}...", filepath); - let fbuffer = FileBuffer::open(&filepath)?; - let digest = hash(&fbuffer); - trace!("Finished hashing {:?}...", &filepath); - Address::Hash(digest) - } + AddressType::File => hash_path(&input)?, AddressType::Sha256sum => { let digest = multibase::Base::Base16Lower.decode(input)?; Address::Hash(upend::util::hash::Hash(digest)) @@ -456,3 +442,12 @@ fn main() -> Result<()> { } } } + +fn hash_path>(filepath: P) -> Result
{ + let filepath = filepath.as_ref(); + debug!("Hashing {:?}...", filepath); + let fbuffer = FileBuffer::open(filepath)?; + let digest = hash(&fbuffer); + trace!("Finished hashing {:?}...", filepath); + Ok(Address::Hash(digest)) +} diff --git a/src/database/stores/fs/mod.rs b/src/database/stores/fs/mod.rs index 62b49a9..da8c35d 100644 --- a/src/database/stores/fs/mod.rs +++ b/src/database/stores/fs/mod.rs @@ -777,7 +777,7 @@ mod test { let job_container = JobContainer::new(); // Store scan - let rescan_result = store.update(&open_result.db, job_container.clone(), false); + let rescan_result = store.update(&open_result.db, job_container, false); assert!(rescan_result.is_ok()); } @@ -821,7 +821,7 @@ mod test { let rescan_result = rescan_result.unwrap(); assert_eq!(rescan_result.len(), 3); rescan_result.into_iter().for_each(|outcome| match outcome { - UpdatePathOutcome::Added(_) => assert!(true), + UpdatePathOutcome::Added(_) => (), UpdatePathOutcome::Skipped(path) => assert_eq!(path, empty_path), outcome => panic!("Unexpected outcome: {:?}", outcome), });