Impl Display for Ref

This commit is contained in:
Matthias Beyer 2016-07-04 19:41:21 +02:00
parent ebf185fd29
commit a29242c586

View file

@ -6,8 +6,10 @@ use std::ops::Deref;
use std::ops::DerefMut;
use std::collections::BTreeMap;
use std::fs::File;
use std::io::Read;
use std::io::{Read, Write};
use std::fmt::{Display, Error as FmtError, Formatter};
use std::fs::Permissions;
use std::result::Result as RResult;
use libimagstore::store::FileLockEntry;
use libimagstore::storeid::StoreId;
@ -495,6 +497,20 @@ impl<'a> DerefMut for Ref<'a> {
}
impl<'a> Display for Ref<'a> {
fn fmt(&self, fmt: &mut Formatter) -> RResult<(), FmtError> {
let path = self.fs_file()
.map(|pb| String::from(pb.to_str().unwrap_or("<UTF8-Error>")))
.unwrap_or(String::from("Could not read Path from reference object"));
let hash = self.get_stored_hash().unwrap_or(String::from("<could not read hash>"));
write!(fmt, "Ref({} -> {})", hash, path)
}
}
fn hash_file_contents(f: &mut File) -> String {
let mut hasher = Sha1::new();
let mut s = String::new();