Fix Ref::get_path_hash() to use ::into_pathbuf()

This commit is contained in:
Matthias Beyer 2016-09-06 12:23:44 +02:00
parent a53adb854d
commit a6377f322e

View file

@ -15,6 +15,7 @@ use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::IntoStoreId;
use libimagstore::store::Store; use libimagstore::store::Store;
use libimagerror::into::IntoError; use libimagerror::into::IntoError;
use libimagerror::trace::MapErrTrace;
use toml::Value; use toml::Value;
@ -230,11 +231,18 @@ impl<'a> Ref<'a> {
/// Get the hash from the path of the ref /// Get the hash from the path of the ref
pub fn get_path_hash(&self) -> Option<String> { pub fn get_path_hash(&self) -> Option<String> {
let pb : PathBuf = self.0.get_location().clone().into(); self.0
.get_location()
.clone()
.into_pathbuf()
.map_err_trace()
.ok() // TODO: Hiding the error here is not so nice
.and_then(|pb| {
pb.file_name() pb.file_name()
.and_then(|osstr| osstr.to_str()) .and_then(|osstr| osstr.to_str())
.and_then(|s| s.split("~").next()) .and_then(|s| s.split("~").next())
.map(String::from) .map(String::from)
})
} }
/// Get the hash of the link target which is stored in the ref object /// Get the hash of the link target which is stored in the ref object