Merge pull request #141 from matthiasbeyer/libimagstore/add-storeid-iter

Libimagstore/add storeid iter
This commit is contained in:
Matthias Beyer 2016-01-24 19:25:53 +01:00
commit 9fbfb9fd37
4 changed files with 32 additions and 1 deletions

View file

@ -5,6 +5,7 @@ authors = ["Matthias Beyer <mail@beyermatthias.de>"]
[dependencies] [dependencies]
fs2 = "0.2.2" fs2 = "0.2.2"
glob = "0.2.10"
regex = "0.1.47" regex = "0.1.47"
semver = "0.2" semver = "0.2"
toml = "0.1.25" toml = "0.1.25"

View file

@ -1,5 +1,6 @@
#[macro_use] extern crate version; #[macro_use] extern crate version;
extern crate fs2; extern crate fs2;
extern crate glob;
extern crate regex; extern crate regex;
extern crate toml; extern crate toml;
#[cfg(test)] extern crate tempdir; #[cfg(test)] extern crate tempdir;

View file

@ -15,7 +15,7 @@ use regex::Regex;
use error::{ParserErrorKind, ParserError}; use error::{ParserErrorKind, ParserError};
use error::{StoreError, StoreErrorKind}; use error::{StoreError, StoreErrorKind};
use storeid::StoreId; use storeid::{StoreId, StoreIdIterator};
use lazyfile::LazyFile; use lazyfile::LazyFile;
/// The Result Type returned by any interaction with the store that could fail /// The Result Type returned by any interaction with the store that could fail
@ -140,6 +140,11 @@ impl Store {
.and_then(|entry| Ok(FileLockEntry::new(self, entry, id))) .and_then(|entry| Ok(FileLockEntry::new(self, entry, id)))
} }
/// Iterate over all StoreIds for one module name
pub fn retrieve_for_module(&self, mod_name: &str) -> StoreIdIterator {
unimplemented!();
}
/// Return the `FileLockEntry` and write to disk /// Return the `FileLockEntry` and write to disk
pub fn update<'a>(&'a self, entry: FileLockEntry<'a>) -> Result<()> { pub fn update<'a>(&'a self, entry: FileLockEntry<'a>) -> Result<()> {
self._update(&entry) self._update(&entry)

View file

@ -1,4 +1,5 @@
use std::path::PathBuf; use std::path::PathBuf;
use glob::Paths;
/// The Index into the Store /// The Index into the Store
pub type StoreId = PathBuf; pub type StoreId = PathBuf;
@ -63,6 +64,29 @@ macro_rules! module_entry_path_mod {
) )
} }
pub struct StoreIdIterator {
paths: Paths,
}
impl StoreIdIterator {
pub fn new(paths: Paths) -> StoreIdIterator {
StoreIdIterator {
paths: paths,
}
}
}
impl Iterator for StoreIdIterator {
type Item = StoreId;
fn next(&mut self) -> Option<StoreId> {
self.paths.next().and_then(|o| o.ok())
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {