Merge pull request #349 from matthiasbeyer/libimagstore/walk
Libimagstore/walk
This commit is contained in:
commit
285832f45f
3 changed files with 60 additions and 0 deletions
|
@ -13,6 +13,7 @@ semver = "0.2"
|
||||||
toml = "0.1.25"
|
toml = "0.1.25"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
crossbeam = "0.2.8"
|
crossbeam = "0.2.8"
|
||||||
|
walkdir = "0.1.5"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempdir = "0.3.4"
|
tempdir = "0.3.4"
|
||||||
|
|
|
@ -22,6 +22,7 @@ extern crate toml;
|
||||||
#[cfg(test)] extern crate tempdir;
|
#[cfg(test)] extern crate tempdir;
|
||||||
extern crate semver;
|
extern crate semver;
|
||||||
extern crate crossbeam;
|
extern crate crossbeam;
|
||||||
|
extern crate walkdir;
|
||||||
|
|
||||||
pub mod storeid;
|
pub mod storeid;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
|
|
@ -20,6 +20,8 @@ use std::fmt::Error as FMTError;
|
||||||
use toml::{Table, Value};
|
use toml::{Table, Value};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
|
use walkdir::WalkDir;
|
||||||
|
use walkdir::Iter as WalkDirIter;
|
||||||
|
|
||||||
use error::{ParserErrorKind, ParserError};
|
use error::{ParserErrorKind, ParserError};
|
||||||
use error::{StoreError, StoreErrorKind};
|
use error::{StoreError, StoreErrorKind};
|
||||||
|
@ -52,6 +54,57 @@ struct StoreEntry {
|
||||||
status: StoreEntryStatus,
|
status: StoreEntryStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum StoreObject {
|
||||||
|
Id(StoreId),
|
||||||
|
Collection(PathBuf),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Walk {
|
||||||
|
dirwalker: WalkDirIter,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Walk {
|
||||||
|
|
||||||
|
fn new(mut store_path: PathBuf, mod_name: &str) -> Walk {
|
||||||
|
store_path.push(mod_name);
|
||||||
|
Walk {
|
||||||
|
dirwalker: WalkDir::new(store_path).into_iter(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ::std::ops::Deref for Walk {
|
||||||
|
type Target = WalkDirIter;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.dirwalker
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Iterator for Walk {
|
||||||
|
type Item = StoreObject;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
while let Some(something) = self.dirwalker.next() {
|
||||||
|
match something {
|
||||||
|
Ok(next) => if next.file_type().is_dir() {
|
||||||
|
return Some(StoreObject::Collection(next.path().to_path_buf()))
|
||||||
|
} else if next.file_type().is_file() {
|
||||||
|
return Some(StoreObject::Id(next.path().to_path_buf().into()))
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
warn!("Error in Walker");
|
||||||
|
debug!("{:?}", e);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
impl StoreEntry {
|
impl StoreEntry {
|
||||||
|
|
||||||
fn new(id: StoreId) -> StoreEntry {
|
fn new(id: StoreId) -> StoreEntry {
|
||||||
|
@ -315,6 +368,11 @@ impl Store {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Walk the store tree for the module
|
||||||
|
pub fn walk<'a>(&'a self, mod_name: &str) -> Walk {
|
||||||
|
Walk::new(self.path().clone(), mod_name)
|
||||||
|
}
|
||||||
|
|
||||||
/// Return the `FileLockEntry` and write to disk
|
/// Return the `FileLockEntry` and write to disk
|
||||||
pub fn update<'a>(&'a self, mut entry: FileLockEntry<'a>) -> Result<()> {
|
pub fn update<'a>(&'a self, mut entry: FileLockEntry<'a>) -> Result<()> {
|
||||||
if let Err(e) = self.execute_hooks_for_mut_file(self.pre_update_aspects.clone(), &mut entry) {
|
if let Err(e) = self.execute_hooks_for_mut_file(self.pre_update_aspects.clone(), &mut entry) {
|
||||||
|
|
Loading…
Reference in a new issue