diff --git a/bin/core/imag-ref/src/main.rs b/bin/core/imag-ref/src/main.rs index 1420f5f8..51fdcaea 100644 --- a/bin/core/imag-ref/src/main.rs +++ b/bin/core/imag-ref/src/main.rs @@ -102,6 +102,7 @@ fn remove(rt: &Runtime) { let yes = cmd.is_present("yes"); if yes || ask_bool(&format!("Delete Ref with hash '{}'", hash)[..], None) { + match rt.store().get_by_partitial_hash( match rt.store().delete_by_hash(hash) { Err(e) => trace_error(&e), Ok(_) => info!("Ok"), diff --git a/lib/entry/libimagentryref/src/refstore.rs b/lib/entry/libimagentryref/src/refstore.rs index b1ac9381..102d3d94 100644 --- a/lib/entry/libimagentryref/src/refstore.rs +++ b/lib/entry/libimagentryref/src/refstore.rs @@ -23,6 +23,7 @@ use std::fs::File; use libimagstore::store::FileLockEntry; use libimagstore::storeid::IntoStoreId; +use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreIdIterator; use libimagstore::store::Store; @@ -47,6 +48,10 @@ pub trait RefStore { /// Returns None if the hash cannot be found. fn get_by_hash<'a>(&'a self, hash: String) -> Result>>; + /// Find a store id by partial ref (also see documentation for + /// `RefStore::get_by_partitial_hash()`. + fn find_storeid_by_partial_hash(&self, hash: &String) -> Result>; + /// Get a Ref object from the store by (eventually partial) hash. /// /// If the hash is complete, `RefStore::get_by_hash()` should be used as it is cheaper. @@ -123,23 +128,32 @@ impl RefStore for Store { .map_err(From::from) } - /// Get a Ref object from the store by (eventually partial) hash. - /// - /// If the hash is complete, `RefStore::get_by_hash()` should be used as it is cheaper. - /// If the hash comes from user input and thus might be abbreviated, this function can be used. - fn get_by_partitial_hash<'a>(&'a self, hash: &String) -> Result>> { + fn find_storeid_by_partial_hash(&self, hash: &String) -> Result> { + debug!("Trying to find '{}' in store...", hash); for id in self.retrieve_for_module("ref")? { let components_have_hash = id .components() .any(|c| c.as_os_str().to_str().map(|s| s.contains(hash)).unwrap_or(false)); if components_have_hash { - return self.get(id).map_err(From::from); + debug!("Found hash '{}' in {:?}", hash, id); + return Ok(Some(id)) } } Ok(None) } + /// Get a Ref object from the store by (eventually partial) hash. + /// + /// If the hash is complete, `RefStore::get_by_hash()` should be used as it is cheaper. + /// If the hash comes from user input and thus might be abbreviated, this function can be used. + fn get_by_partitial_hash<'a>(&'a self, hash: &String) -> Result>> { + match self.find_storeid_by_partial_hash(hash)? { + Some(id) => self.get(id).map_err(From::from), + None => Ok(None), + } + } + /// Delete a ref by hash /// /// If the returned Result contains an error, the ref might not be deleted.