diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-03-26 14:59:03 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-03-26 15:28:18 +0100 |
commit | 5fe843e5d6064b99e802f5793bc052d8355047a9 (patch) | |
tree | cb909364298203d981f4bc7a66bf30f6b45a34cf /libimagentrylist | |
parent | 52eb81a6f78833a2b3135f55b407e3123e789f06 (diff) |
Add simple PathLister type
Diffstat (limited to 'libimagentrylist')
-rw-r--r-- | libimagentrylist/src/lib.rs | 1 | ||||
-rw-r--r-- | libimagentrylist/src/listers/mod.rs | 1 | ||||
-rw-r--r-- | libimagentrylist/src/listers/path.rs | 54 |
3 files changed, 56 insertions, 0 deletions
diff --git a/libimagentrylist/src/lib.rs b/libimagentrylist/src/lib.rs index b47d1f2e..c9c369fa 100644 --- a/libimagentrylist/src/lib.rs +++ b/libimagentrylist/src/lib.rs @@ -5,5 +5,6 @@ extern crate libimagstore; pub mod error; pub mod lister; +pub mod listers; pub mod result; diff --git a/libimagentrylist/src/listers/mod.rs b/libimagentrylist/src/listers/mod.rs new file mode 100644 index 00000000..4da97892 --- /dev/null +++ b/libimagentrylist/src/listers/mod.rs @@ -0,0 +1 @@ +pub mod path; diff --git a/libimagentrylist/src/listers/path.rs b/libimagentrylist/src/listers/path.rs new file mode 100644 index 00000000..285802e2 --- /dev/null +++ b/libimagentrylist/src/listers/path.rs @@ -0,0 +1,54 @@ +use std::io::stdout; +use std::io::Write; +use std::ops::Deref; + +use lister::Lister; +use result::Result; + +use libimagstore::store::FileLockEntry; + +pub struct PathLister { + absolute: bool, +} + +impl PathLister { + + pub fn new(absolute: bool) -> PathLister { + PathLister { + absolute: absolute, + } + } + +} + +impl Lister for PathLister { + + fn list<'a, I: Iterator<Item = FileLockEntry<'a>>>(&self, entries: I) -> Result<()> { + use error::ListError as LE; + use error::ListErrorKind as LEK; + + entries.fold(Ok(()), |accu, entry| { + accu.and_then(|_| Ok(entry.deref().get_location().clone())) + .and_then(|pb| { + if self.absolute { + pb.canonicalize().map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e)))) + } else { + Ok(pb) + } + }) + .and_then(|pb| { + write!(stdout(), "{:?}\n", pb) + .map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e)))) + }) + .map_err(|e| { + if e.err_type() == LEK::FormatError { + e + } else { + LE::new(LEK::FormatError, Some(Box::new(e))) + } + }) + }) + } + +} + |