Use ? operator instead of try!() macro

This commit is contained in:
Matthias Beyer 2017-10-21 16:17:35 +02:00
parent ea618ee3c7
commit 5d76e7bafa
8 changed files with 87 additions and 89 deletions

View file

@ -48,8 +48,8 @@ impl FileAbstractionInstance for FSFileAbstractionInstance {
FSFileAbstractionInstance::File(ref mut f, _) => return { FSFileAbstractionInstance::File(ref mut f, _) => return {
// We seek to the beginning of the file since we expect each // We seek to the beginning of the file since we expect each
// access to the file to be in a different context // access to the file to be in a different context
try!(f.seek(SeekFrom::Start(0)) f.seek(SeekFrom::Start(0))
.chain_err(|| SEK::FileNotSeeked)); .chain_err(|| SEK::FileNotSeeked)?;
let mut s = String::new(); let mut s = String::new();
f.read_to_string(&mut s) f.read_to_string(&mut s)
@ -58,7 +58,7 @@ impl FileAbstractionInstance for FSFileAbstractionInstance {
.and_then(|s| Entry::from_str(id, &s)) .and_then(|s| Entry::from_str(id, &s))
}, },
FSFileAbstractionInstance::Absent(ref p) => FSFileAbstractionInstance::Absent(ref p) =>
(try!(open_file(p).chain_err(|| SEK::FileNotFound)), p.clone()), (open_file(p).chain_err(|| SEK::FileNotFound)?, p.clone()),
}; };
*self = FSFileAbstractionInstance::File(file, path); *self = FSFileAbstractionInstance::File(file, path);
if let FSFileAbstractionInstance::File(ref mut f, _) = *self { if let FSFileAbstractionInstance::File(ref mut f, _) = *self {
@ -84,15 +84,15 @@ impl FileAbstractionInstance for FSFileAbstractionInstance {
FSFileAbstractionInstance::File(ref mut f, _) => return { FSFileAbstractionInstance::File(ref mut f, _) => return {
// We seek to the beginning of the file since we expect each // We seek to the beginning of the file since we expect each
// access to the file to be in a different context // access to the file to be in a different context
try!(f.seek(SeekFrom::Start(0)) f.seek(SeekFrom::Start(0))
.chain_err(|| SEK::FileNotCreated)); .chain_err(|| SEK::FileNotCreated)?;
try!(f.set_len(buf.len() as u64).chain_err(|| SEK::FileNotWritten)); f.set_len(buf.len() as u64).chain_err(|| SEK::FileNotWritten)?;
f.write_all(&buf).chain_err(|| SEK::FileNotWritten) f.write_all(&buf).chain_err(|| SEK::FileNotWritten)
}, },
FSFileAbstractionInstance::Absent(ref p) => FSFileAbstractionInstance::Absent(ref p) =>
(try!(create_file(p).chain_err(|| SEK::FileNotCreated)), p.clone()), (create_file(p).chain_err(|| SEK::FileNotCreated)?, p.clone()),
}; };
*self = FSFileAbstractionInstance::File(file, path); *self = FSFileAbstractionInstance::File(file, path);
if let FSFileAbstractionInstance::File(ref mut f, _) = *self { if let FSFileAbstractionInstance::File(ref mut f, _) = *self {
@ -129,7 +129,7 @@ impl FileAbstraction for FSFileAbstraction {
match to.parent() { match to.parent() {
Some(p) => if !p.exists() { Some(p) => if !p.exists() {
debug!("Creating: {:?}", p); debug!("Creating: {:?}", p);
let _ = try!(create_dir_all(&PathBuf::from(p))); let _ = create_dir_all(&PathBuf::from(p))?;
}, },
None => { None => {
debug!("Failed to find parent. This looks like it will fail now"); debug!("Failed to find parent. This looks like it will fail now");
@ -184,11 +184,11 @@ impl FileAbstraction for FSFileAbstraction {
}) })
.fold(Ok(vec![]), |acc, e| { .fold(Ok(vec![]), |acc, e| {
acc.and_then(move |mut a| { acc.and_then(move |mut a| {
a.push(try!(e)); a.push(e?);
Ok(a) Ok(a)
}) })
}); });
Ok(PathIterator::new(Box::new(try!(i).into_iter()))) Ok(PathIterator::new(Box::new(i?.into_iter())))
} }
} }

View file

@ -131,7 +131,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
let mut mtx = self.backend().lock().expect("Locking Mutex failed"); let mut mtx = self.backend().lock().expect("Locking Mutex failed");
let backend = mtx.get_mut(); let backend = mtx.get_mut();
let a = try!(backend.get(from).cloned().ok_or(SE::from_kind(SEK::FileNotFound))); let a = backend.get(from).cloned().ok_or(SE::from_kind(SEK::FileNotFound))?;
backend.insert(to.clone(), a); backend.insert(to.clone(), a);
debug!("Copying: {:?} -> {:?} worked", from, to); debug!("Copying: {:?} -> {:?} worked", from, to);
Ok(()) Ok(())
@ -142,7 +142,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
let mut mtx = self.backend().lock().expect("Locking Mutex failed"); let mut mtx = self.backend().lock().expect("Locking Mutex failed");
let backend = mtx.get_mut(); let backend = mtx.get_mut();
let a = try!(backend.get(from).cloned().ok_or(SE::from_kind(SEK::FileNotFound))); let a = backend.get(from).cloned().ok_or(SE::from_kind(SEK::FileNotFound))?;
backend.insert(to.clone(), a); backend.insert(to.clone(), a);
debug!("Renaming: {:?} -> {:?} worked", from, to); debug!("Renaming: {:?} -> {:?} worked", from, to);
Ok(()) Ok(())
@ -176,7 +176,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
fn fill<'a>(&'a mut self, mut d: Drain) -> Result<(), SE> { fn fill<'a>(&'a mut self, mut d: Drain) -> Result<(), SE> {
debug!("Draining into : {:?}", self); debug!("Draining into : {:?}", self);
let mut mtx = try!(self.backend().lock().map_err(|_| SEK::LockError)); let mut mtx = self.backend().lock().map_err(|_| SEK::LockError)?;
let backend = mtx.get_mut(); let backend = mtx.get_mut();
for (path, element) in d.iter() { for (path, element) in d.iter() {

View file

@ -73,15 +73,15 @@ impl Mapper for JsonMapper {
let mut document = { let mut document = {
debug!("Reading Document"); debug!("Reading Document");
let mut s = String::new(); let mut s = String::new();
try!(r.read_to_string(&mut s).chain_err(|| SEK::IoError)); r.read_to_string(&mut s).chain_err(|| SEK::IoError)?;
debug!("Document = {:?}", s); debug!("Document = {:?}", s);
debug!("Parsing Document"); debug!("Parsing Document");
let doc : Document = try!(serde_json::from_str(&s).chain_err(|| SEK::IoError)); let doc : Document = serde_json::from_str(&s).chain_err(|| SEK::IoError)?;
debug!("Document = {:?}", doc); debug!("Document = {:?}", doc);
doc doc
}; };
let _ = try!(::semver::Version::parse(&document.version) let _ = ::semver::Version::parse(&document.version)
.chain_err(|| SEK::VersionError) .chain_err(|| SEK::VersionError)
.and_then(|doc_vers| { .and_then(|doc_vers| {
// safe because cargo does not compile if crate version is not valid // safe because cargo does not compile if crate version is not valid
@ -96,7 +96,7 @@ impl Mapper for JsonMapper {
} else { } else {
Ok(()) Ok(())
} }
})); })?;
for (key, val) in document.store.drain() { for (key, val) in document.store.drain() {
debug!("(key, value) ({:?}, {:?})", key, val); debug!("(key, value) ({:?}, {:?})", key, val);
@ -110,7 +110,7 @@ impl Mapper for JsonMapper {
}) })
.map(|_| ()); .map(|_| ());
let _ = try!(res); let _ = res?;
} }
Ok(()) Ok(())

View file

@ -56,11 +56,10 @@ impl<W, M> StdIoFileAbstraction<W, M>
pub fn new<R: Read>(in_stream: &mut R, out_stream: Rc<RefCell<W>>, mapper: M) -> Result<StdIoFileAbstraction<W, M>, SE> { pub fn new<R: Read>(in_stream: &mut R, out_stream: Rc<RefCell<W>>, mapper: M) -> Result<StdIoFileAbstraction<W, M>, SE> {
StdoutFileAbstraction::new(out_stream, mapper) StdoutFileAbstraction::new(out_stream, mapper)
.and_then(|out| { .and_then(|out| {
let _ = try!(out let _ = out.backend()
.backend() .lock()
.lock() .map_err(|_| SE::from_kind(SEK::LockError))
.map_err(|_| SE::from_kind(SEK::LockError)) .map(|mut mtx| out.mapper().read_to_fs(in_stream, mtx.get_mut()))?;
.map(|mut mtx| out.mapper().read_to_fs(in_stream, mtx.get_mut())));
Ok(StdIoFileAbstraction(out)) Ok(StdIoFileAbstraction(out))
}) })

View file

@ -150,7 +150,7 @@ impl<W: Write, M: Mapper> FileAbstraction for StdoutFileAbstraction<W, M> {
fn fill(&mut self, mut d: Drain) -> Result<(), SE> { fn fill(&mut self, mut d: Drain) -> Result<(), SE> {
debug!("Draining into : {:?}", self); debug!("Draining into : {:?}", self);
let mut mtx = try!(self.backend().lock().map_err(|_| SE::from_kind(SEK::IoError))); let mut mtx = self.backend().lock().map_err(|_| SE::from_kind(SEK::IoError))?;
let backend = mtx.get_mut(); let backend = mtx.get_mut();
for (path, element) in d.iter() { for (path, element) in d.iter() {

View file

@ -140,13 +140,13 @@ impl Iterator for Walk {
impl StoreEntry { impl StoreEntry {
fn new(id: StoreId, backend: &Box<FileAbstraction>) -> Result<StoreEntry> { fn new(id: StoreId, backend: &Box<FileAbstraction>) -> Result<StoreEntry> {
let pb = try!(id.clone().into_pathbuf()); let pb = id.clone().into_pathbuf()?;
#[cfg(feature = "fs-lock")] #[cfg(feature = "fs-lock")]
{ {
try!(open_file(pb.clone()) open_file(pb.clone())
.and_then(|f| f.lock_exclusive()) .and_then(|f| f.lock_exclusive())
.chain_err(|| SEK::IoError)); .chain_err(|| SEK::IoError)?;
} }
Ok(StoreEntry { Ok(StoreEntry {
@ -258,7 +258,7 @@ impl Store {
use configuration::*; use configuration::*;
debug!("Validating Store configuration"); debug!("Validating Store configuration");
let _ = try!(config_is_valid(&store_config).chain_err(|| SEK::ConfigurationError)); let _ = config_is_valid(&store_config).chain_err(|| SEK::ConfigurationError)?;
debug!("Building new Store object"); debug!("Building new Store object");
if !location.exists() { if !location.exists() {
@ -268,9 +268,10 @@ impl Store {
.chain_err(|| SEK::IoError); .chain_err(|| SEK::IoError);
} }
try!(backend.create_dir_all(&location) backend
.chain_err(|| SEK::StorePathCreate(location.clone())) .create_dir_all(&location)
.map_dbg_err_str("Failed")); .chain_err(|| SEK::StorePathCreate(location.clone()))
.map_dbg_err_str("Failed")?;
} else if location.is_file() { } else if location.is_file() {
debug!("Store path exists as file"); debug!("Store path exists as file");
return Err(SE::from_kind(SEK::StorePathExists(location))); return Err(SE::from_kind(SEK::StorePathExists(location)));
@ -391,7 +392,7 @@ impl Store {
/// - CreateCallError(EntryAlreadyExists()) if the entry exists already. /// - CreateCallError(EntryAlreadyExists()) if the entry exists already.
/// ///
pub fn create<'a, S: IntoStoreId>(&'a self, id: S) -> Result<FileLockEntry<'a>> { pub fn create<'a, S: IntoStoreId>(&'a self, id: S) -> Result<FileLockEntry<'a>> {
let id = try!(id.into_storeid()).with_base(self.path().clone()); let id = id.into_storeid()?.with_base(self.path().clone());
debug!("Creating id: '{}'", id); debug!("Creating id: '{}'", id);
@ -408,7 +409,7 @@ impl Store {
} }
hsmap.insert(id.clone(), { hsmap.insert(id.clone(), {
debug!("Creating: '{}'", id); debug!("Creating: '{}'", id);
let mut se = try!(StoreEntry::new(id.clone(), &self.backend)); let mut se = StoreEntry::new(id.clone(), &self.backend)?;
se.status = StoreEntryStatus::Borrowed; se.status = StoreEntryStatus::Borrowed;
se se
}); });
@ -434,21 +435,20 @@ impl Store {
/// - RetrieveCallError(LockPoisoned()) if the internal lock is poisened. /// - RetrieveCallError(LockPoisoned()) if the internal lock is poisened.
/// ///
pub fn retrieve<'a, S: IntoStoreId>(&'a self, id: S) -> Result<FileLockEntry<'a>> { pub fn retrieve<'a, S: IntoStoreId>(&'a self, id: S) -> Result<FileLockEntry<'a>> {
let id = try!(id.into_storeid()).with_base(self.path().clone()); let id = id.into_storeid()?.with_base(self.path().clone());
debug!("Retrieving id: '{}'", id); debug!("Retrieving id: '{}'", id);
let entry = try!({ let entry = self
self.entries .entries
.write() .write()
.map_err(|_| SE::from_kind(SEK::LockPoisoned)) .map_err(|_| SE::from_kind(SEK::LockPoisoned))
.and_then(|mut es| { .and_then(|mut es| {
let new_se = try!(StoreEntry::new(id.clone(), &self.backend)); let new_se = StoreEntry::new(id.clone(), &self.backend)?;
let se = es.entry(id.clone()).or_insert(new_se); let se = es.entry(id.clone()).or_insert(new_se);
let entry = se.get_entry(); let entry = se.get_entry();
se.status = StoreEntryStatus::Borrowed; se.status = StoreEntryStatus::Borrowed;
entry entry
}) })
.chain_err(|| SEK::RetrieveCallError) .chain_err(|| SEK::RetrieveCallError)?;
});
debug!("Constructing FileLockEntry: '{}'", id); debug!("Constructing FileLockEntry: '{}'", id);
Ok(FileLockEntry::new(self, entry)) Ok(FileLockEntry::new(self, entry))
@ -465,16 +465,15 @@ impl Store {
/// - Errors Store::retrieve() might return /// - Errors Store::retrieve() might return
/// ///
pub fn get<'a, S: IntoStoreId + Clone>(&'a self, id: S) -> Result<Option<FileLockEntry<'a>>> { pub fn get<'a, S: IntoStoreId + Clone>(&'a self, id: S) -> Result<Option<FileLockEntry<'a>>> {
let id = try!(id.into_storeid()).with_base(self.path().clone()); let id = id.into_storeid()?.with_base(self.path().clone());
debug!("Getting id: '{}'", id); debug!("Getting id: '{}'", id);
let exists = try!(id.exists()) || try!(self.entries let exists = id.exists()? || self.entries
.read() .read()
.map(|map| map.contains_key(&id)) .map(|map| map.contains_key(&id))
.map_err(|_| SE::from_kind(SEK::LockPoisoned)) .map_err(|_| SE::from_kind(SEK::LockPoisoned))
.chain_err(|| SEK::GetCallError) .chain_err(|| SEK::GetCallError)?;
);
if !exists { if !exists {
debug!("Does not exist in internal cache or filesystem: {:?}", id); debug!("Does not exist in internal cache or filesystem: {:?}", id);
@ -558,17 +557,17 @@ impl Store {
Ok(e) => e, Ok(e) => e,
}; };
let se = try!(hsmap.get_mut(&entry.location).ok_or_else(|| { let se = hsmap.get_mut(&entry.location).ok_or_else(|| {
SE::from_kind(SEK::IdNotFound(entry.location.clone())) SE::from_kind(SEK::IdNotFound(entry.location.clone()))
})); })?;
assert!(se.is_borrowed(), "Tried to update a non borrowed entry."); assert!(se.is_borrowed(), "Tried to update a non borrowed entry.");
debug!("Verifying Entry"); debug!("Verifying Entry");
try!(entry.entry.verify()); entry.entry.verify()?;
debug!("Writing Entry"); debug!("Writing Entry");
try!(se.write_entry(&entry.entry)); se.write_entry(&entry.entry)?;
if modify_presence { if modify_presence {
debug!("Modifying ppresence of {} -> Present", entry.get_location()); debug!("Modifying ppresence of {} -> Present", entry.get_location());
se.status = StoreEntryStatus::Present; se.status = StoreEntryStatus::Present;
@ -590,7 +589,7 @@ impl Store {
/// - Errors StoreEntry::new() might return /// - Errors StoreEntry::new() might return
/// ///
pub fn retrieve_copy<S: IntoStoreId>(&self, id: S) -> Result<Entry> { pub fn retrieve_copy<S: IntoStoreId>(&self, id: S) -> Result<Entry> {
let id = try!(id.into_storeid()).with_base(self.path().clone()); let id = id.into_storeid()?.with_base(self.path().clone());
debug!("Retrieving copy of '{}'", id); debug!("Retrieving copy of '{}'", id);
let entries = match self.entries.write() { let entries = match self.entries.write() {
Err(_) => { Err(_) => {
@ -605,7 +604,7 @@ impl Store {
return Err(SE::from_kind(SEK::IdLocked)).chain_err(|| SEK::RetrieveCopyCallError); return Err(SE::from_kind(SEK::IdLocked)).chain_err(|| SEK::RetrieveCopyCallError);
} }
try!(StoreEntry::new(id, &self.backend)).get_entry() StoreEntry::new(id, &self.backend)?.get_entry()
} }
/// Delete an entry /// Delete an entry
@ -620,7 +619,7 @@ impl Store {
/// - DeleteCallError(FileError()) if the internals failed to remove the file. /// - DeleteCallError(FileError()) if the internals failed to remove the file.
/// ///
pub fn delete<S: IntoStoreId>(&self, id: S) -> Result<()> { pub fn delete<S: IntoStoreId>(&self, id: S) -> Result<()> {
let id = try!(id.into_storeid()).with_base(self.path().clone()); let id = id.into_storeid()?.with_base(self.path().clone());
debug!("Deleting id: '{}'", id); debug!("Deleting id: '{}'", id);
@ -641,7 +640,7 @@ impl Store {
// StoreId::exists(), a PathBuf object gets allocated. So we simply get a // StoreId::exists(), a PathBuf object gets allocated. So we simply get a
// PathBuf here, check whether it is there and if it is, we can re-use it to // PathBuf here, check whether it is there and if it is, we can re-use it to
// delete the filesystem file. // delete the filesystem file.
let pb = try!(id.into_pathbuf()); let pb = id.into_pathbuf()?;
if pb.exists() { if pb.exists() {
// looks like we're deleting a not-loaded file from the store. // looks like we're deleting a not-loaded file from the store.
@ -660,7 +659,7 @@ impl Store {
// remove the entry first, then the file // remove the entry first, then the file
entries.remove(&id); entries.remove(&id);
let pb = try!(id.clone().with_base(self.path().clone()).into_pathbuf()); let pb = id.clone().with_base(self.path().clone()).into_pathbuf()?;
if let Err(e) = self.backend.remove_file(&pb) { if let Err(e) = self.backend.remove_file(&pb) {
return Err(e) return Err(e)
.chain_err(|| SEK::FileError) .chain_err(|| SEK::FileError)
@ -689,12 +688,11 @@ impl Store {
-> Result<()> -> Result<()>
{ {
let new_id = new_id.with_base(self.path().clone()); let new_id = new_id.with_base(self.path().clone());
let hsmap = try!( let hsmap = self
self.entries .entries
.write() .write()
.map_err(|_| SE::from_kind(SEK::LockPoisoned)) .map_err(|_| SE::from_kind(SEK::LockPoisoned))
.chain_err(|| SEK::MoveCallError) .chain_err(|| SEK::MoveCallError)?;
);
if hsmap.contains_key(&new_id) { if hsmap.contains_key(&new_id) {
return Err(SE::from_kind(SEK::EntryAlreadyExists(new_id.clone()))) return Err(SE::from_kind(SEK::EntryAlreadyExists(new_id.clone())))
@ -703,8 +701,8 @@ impl Store {
let old_id = entry.get_location().clone(); let old_id = entry.get_location().clone();
let old_id_as_path = try!(old_id.clone().with_base(self.path().clone()).into_pathbuf()); let old_id_as_path = old_id.clone().with_base(self.path().clone()).into_pathbuf()?;
let new_id_as_path = try!(new_id.clone().with_base(self.path().clone()).into_pathbuf()); let new_id_as_path = new_id.clone().with_base(self.path().clone()).into_pathbuf()?;
self.backend.copy(&old_id_as_path, &new_id_as_path) self.backend.copy(&old_id_as_path, &new_id_as_path)
.and_then(|_| { .and_then(|_| {
if remove_old { if remove_old {
@ -777,10 +775,10 @@ impl Store {
debug!("Old id is not yet borrowed"); debug!("Old id is not yet borrowed");
let old_id_pb = try!(old_id.clone().with_base(self.path().clone()).into_pathbuf()); let old_id_pb = old_id.clone().with_base(self.path().clone()).into_pathbuf()?;
let new_id_pb = try!(new_id.clone().with_base(self.path().clone()).into_pathbuf()); let new_id_pb = new_id.clone().with_base(self.path().clone()).into_pathbuf()?;
if try!(self.backend.exists(&new_id_pb)) { if self.backend.exists(&new_id_pb)? {
return Err(SE::from_kind(SEK::EntryAlreadyExists(new_id.clone()))); return Err(SE::from_kind(SEK::EntryAlreadyExists(new_id.clone())));
} }
debug!("New entry does not yet exist on filesystem. Good."); debug!("New entry does not yet exist on filesystem. Good.");
@ -817,11 +815,12 @@ impl Store {
let is_file = { let is_file = {
let mut base = self.path().clone(); let mut base = self.path().clone();
base.push(element.clone()); base.push(element.clone());
try!(self.backend.is_file(&base)) println!("Checking: {:?}", base);
self.backend.is_file(&base)?
}; };
if is_file { if is_file {
let sid = try!(StoreId::from_full_path(self.path(), element)); let sid = StoreId::from_full_path(self.path(), element)?;
elems.push(sid); elems.push(sid);
} }
} }
@ -841,14 +840,14 @@ impl Debug for Store {
/// TODO: Make pretty. /// TODO: Make pretty.
fn fmt(&self, fmt: &mut Formatter) -> RResult<(), FMTError> { fn fmt(&self, fmt: &mut Formatter) -> RResult<(), FMTError> {
try!(write!(fmt, " --- Store ---\n")); write!(fmt, " --- Store ---\n")?;
try!(write!(fmt, "\n")); write!(fmt, "\n")?;
try!(write!(fmt, " - location : {:?}\n", self.location)); write!(fmt, " - location : {:?}\n", self.location)?;
try!(write!(fmt, " - configuration : {:?}\n", self.configuration)); write!(fmt, " - configuration : {:?}\n", self.configuration)?;
try!(write!(fmt, "\n")); write!(fmt, "\n")?;
try!(write!(fmt, "Entries:\n")); write!(fmt, "Entries:\n")?;
try!(write!(fmt, "{:?}", self.entries)); write!(fmt, "{:?}", self.entries)?;
try!(write!(fmt, "\n")); write!(fmt, "\n")?;
Ok(()) Ok(())
} }
@ -979,7 +978,7 @@ impl Entry {
pub fn from_reader<S: IntoStoreId>(loc: S, file: &mut Read) -> Result<Entry> { pub fn from_reader<S: IntoStoreId>(loc: S, file: &mut Read) -> Result<Entry> {
let text = { let text = {
let mut s = String::new(); let mut s = String::new();
try!(file.read_to_string(&mut s)); file.read_to_string(&mut s)?;
s s
}; };
Self::from_str(loc, &text[..]) Self::from_str(loc, &text[..])
@ -1000,10 +999,10 @@ impl Entry {
pub fn from_str<S: IntoStoreId>(loc: S, s: &str) -> Result<Entry> { pub fn from_str<S: IntoStoreId>(loc: S, s: &str) -> Result<Entry> {
use util::entry_buffer_to_header_content; use util::entry_buffer_to_header_content;
let (header, content) = try!(entry_buffer_to_header_content(s)); let (header, content) = entry_buffer_to_header_content(s)?;
Ok(Entry { Ok(Entry {
location: try!(loc.into_storeid()), location: loc.into_storeid()?,
header: header, header: header,
content: content, content: content,
}) })

View file

@ -59,9 +59,9 @@ impl StoreId {
pub fn from_full_path<D>(store_part: &PathBuf, full_path: D) -> Result<StoreId> pub fn from_full_path<D>(store_part: &PathBuf, full_path: D) -> Result<StoreId>
where D: Deref<Target = Path> where D: Deref<Target = Path>
{ {
let p = try!( let p = full_path
full_path.strip_prefix(store_part).chain_err(|| SEK::StoreIdBuildFromFullPathError) .strip_prefix(store_part)
); .chain_err(|| SEK::StoreIdBuildFromFullPathError)?;
StoreId::new(Some(store_part.clone()), PathBuf::from(p)) StoreId::new(Some(store_part.clone()), PathBuf::from(p))
} }
@ -91,7 +91,7 @@ impl StoreId {
/// specified. /// specified.
pub fn into_pathbuf(mut self) -> Result<PathBuf> { pub fn into_pathbuf(mut self) -> Result<PathBuf> {
let base = self.base.take(); let base = self.base.take();
let mut base = try!(base.ok_or_else(|| SEK::StoreIdHasNoBaseError(self.id.clone()))); let mut base = base.ok_or_else(|| SEK::StoreIdHasNoBaseError(self.id.clone()))?;
base.push(self.id); base.push(self.id);
Ok(base) Ok(base)
} }

View file

@ -64,6 +64,6 @@ pub fn entry_buffer_to_header_content(buf: &str) -> Result<(Value, String)> {
let content = matches.name("content").map(|r| r.as_str()).unwrap_or(""); let content = matches.name("content").map(|r| r.as_str()).unwrap_or("");
Ok((try!(Value::parse(header.as_str())), String::from(content))) Ok((Value::parse(header.as_str())?, String::from(content)))
} }