Implement Ref functions
This commit is contained in:
parent
ed69fd4b35
commit
cbb47cffcb
|
@ -42,7 +42,7 @@ pub trait Ref {
|
||||||
/// Get the stored hash.
|
/// Get the stored hash.
|
||||||
///
|
///
|
||||||
/// Does not need a `UniqueRefPathGenerator` as it reads the hash stored in the header
|
/// Does not need a `UniqueRefPathGenerator` as it reads the hash stored in the header
|
||||||
fn get_hash(&self) -> Result<String>;
|
fn get_hash(&self) -> Result<&str>;
|
||||||
|
|
||||||
/// Get the referenced path.
|
/// Get the referenced path.
|
||||||
///
|
///
|
||||||
|
@ -50,12 +50,7 @@ pub trait Ref {
|
||||||
fn get_path(&self) -> Result<PathBuf>;
|
fn get_path(&self) -> Result<PathBuf>;
|
||||||
|
|
||||||
/// Check whether the referenced file still matches its hash
|
/// Check whether the referenced file still matches its hash
|
||||||
fn hash_valid<RPG: UniqueRefPathGenerator>(&self) -> Result<bool>;
|
fn hash_valid<RPG: UniqueRefPathGenerator>(&self) -> RResult<bool, RPG::Error>;
|
||||||
|
|
||||||
/// Update the stored hash
|
|
||||||
///
|
|
||||||
/// This updates the hash in the header and moves the entry to the appropriate location
|
|
||||||
fn update_hash<RPG: UniqueRefPathGenerator>(&mut self, store: &Store) -> Result<bool>;
|
|
||||||
|
|
||||||
/// Alias for `r.fs_link_exists() && r.deref().is_file()`
|
/// Alias for `r.fs_link_exists() && r.deref().is_file()`
|
||||||
fn is_ref_to_file(&self) -> Result<bool> {
|
fn is_ref_to_file(&self) -> Result<bool> {
|
||||||
|
@ -83,20 +78,30 @@ impl Ref for Entry {
|
||||||
self.is::<IsRef>().map_err(From::from)
|
self.is::<IsRef>().map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_hash(&self) -> Result<String> {
|
fn get_hash(&self) -> Result<&str> {
|
||||||
unimplemented!()
|
self.get_header()
|
||||||
|
.read("ref.hash")
|
||||||
|
.map_err(RE::from)?
|
||||||
|
.ok_or_else(|| REK::HeaderFieldMissingError("ref.hash").into())
|
||||||
|
.and_then(|v| v.as_str().ok_or_else(|| REK::HeaderTypeError("ref.hash", "string").into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_path(&self) -> Result<PathBuf> {
|
fn get_path(&self) -> Result<PathBuf> {
|
||||||
unimplemented!()
|
self.get_header()
|
||||||
|
.read("ref.path")
|
||||||
|
.map_err(RE::from)?
|
||||||
|
.ok_or_else(|| REK::HeaderFieldMissingError("ref.path").into())
|
||||||
|
.and_then(|v| v.as_str().ok_or_else(|| REK::HeaderTypeError("ref.path", "string").into()))
|
||||||
|
.map(PathBuf::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash_valid<RPG: UniqueRefPathGenerator>(&self) -> Result<bool> {
|
fn hash_valid<RPG: UniqueRefPathGenerator>(&self) -> RResult<bool, RPG::Error> {
|
||||||
unimplemented!()
|
self.get_path()
|
||||||
}
|
.map(PathBuf::from)
|
||||||
|
.map_err(RE::from)
|
||||||
fn update_hash<RPG: UniqueRefPathGenerator>(&mut self, store: &Store) -> Result<bool> {
|
.map_err(RPG::Error::from)
|
||||||
unimplemented!()
|
.and_then(|pb| RPG::unique_hash(pb))
|
||||||
|
.and_then(|h| Ok(h == self.get_hash()?))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue