Merge pull request #710 from matthiasbeyer/libimagstore/fix-globstoreiditerator
libimagstore/fix GlobStoreIdIterator
This commit is contained in:
commit
12f4012384
3 changed files with 23 additions and 1 deletions
|
@ -43,6 +43,7 @@ generate_custom_error_types!(StoreError, StoreErrorKind, CustomErrorData,
|
||||||
EntryRenameError => "Entry rename error",
|
EntryRenameError => "Entry rename error",
|
||||||
StoreIdHandlingError => "StoreId handling error",
|
StoreIdHandlingError => "StoreId handling error",
|
||||||
StoreIdLocalPartAbsoluteError => "StoreId 'id' part is absolute (starts with '/') which is not allowed",
|
StoreIdLocalPartAbsoluteError => "StoreId 'id' part is absolute (starts with '/') which is not allowed",
|
||||||
|
StoreIdBuildFromFullPathError => "Building StoreId from full file path failed",
|
||||||
|
|
||||||
CreateCallError => "Error when calling create()",
|
CreateCallError => "Error when calling create()",
|
||||||
RetrieveCallError => "Error when calling retrieve()",
|
RetrieveCallError => "Error when calling retrieve()",
|
||||||
|
|
|
@ -1503,6 +1503,8 @@ mod glob_store_iter {
|
||||||
impl GlobStoreIdIterator {
|
impl GlobStoreIdIterator {
|
||||||
|
|
||||||
pub fn new(paths: Paths, store_path: PathBuf) -> GlobStoreIdIterator {
|
pub fn new(paths: Paths, store_path: PathBuf) -> GlobStoreIdIterator {
|
||||||
|
debug!("Create a GlobStoreIdIterator(store_path = {:?}, /* ... */)", store_path);
|
||||||
|
|
||||||
GlobStoreIdIterator {
|
GlobStoreIdIterator {
|
||||||
store_path: store_path,
|
store_path: store_path,
|
||||||
paths: paths,
|
paths: paths,
|
||||||
|
@ -1518,8 +1520,9 @@ mod glob_store_iter {
|
||||||
self.paths
|
self.paths
|
||||||
.next()
|
.next()
|
||||||
.and_then(|o| {
|
.and_then(|o| {
|
||||||
|
debug!("GlobStoreIdIterator::next() => {:?}", o);
|
||||||
o.map_err_into(SEK::StoreIdHandlingError)
|
o.map_err_into(SEK::StoreIdHandlingError)
|
||||||
.and_then(|p| StoreId::new(Some(self.store_path.clone()), p))
|
.and_then(|p| StoreId::from_full_path(&self.store_path, p))
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
debug!("GlobStoreIdIterator error: {:?}", e);
|
debug!("GlobStoreIdIterator error: {:?}", e);
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::ops::Deref;
|
||||||
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use std::fmt::{Display, Debug, Formatter};
|
use std::fmt::{Display, Debug, Formatter};
|
||||||
|
@ -8,6 +10,7 @@ use std::path::Components;
|
||||||
use libimagerror::into::IntoError;
|
use libimagerror::into::IntoError;
|
||||||
|
|
||||||
use error::StoreErrorKind as SEK;
|
use error::StoreErrorKind as SEK;
|
||||||
|
use error::MapErrInto;
|
||||||
use store::Result;
|
use store::Result;
|
||||||
use store::Store;
|
use store::Store;
|
||||||
|
|
||||||
|
@ -24,6 +27,21 @@ impl StoreId {
|
||||||
StoreId::new_baseless(id).map(|mut sid| { sid.base = base; sid })
|
StoreId::new_baseless(id).map(|mut sid| { sid.base = base; sid })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Try to create a StoreId object from a filesystem-absolute path.
|
||||||
|
///
|
||||||
|
/// Automatically creates a StoreId object which has a `base` set to `store_part` if stripping
|
||||||
|
/// the `store_part` from the `full_path` succeeded.
|
||||||
|
///
|
||||||
|
/// Returns a `StoreErrorKind::StoreIdBuildFromFullPathError` if stripping failes.
|
||||||
|
pub fn from_full_path<D>(store_part: &PathBuf, full_path: D) -> Result<StoreId>
|
||||||
|
where D: Deref<Target = Path>
|
||||||
|
{
|
||||||
|
let p = try!(
|
||||||
|
full_path.strip_prefix(store_part).map_err_into(SEK::StoreIdBuildFromFullPathError)
|
||||||
|
);
|
||||||
|
StoreId::new(Some(store_part.clone()), PathBuf::from(p))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new_baseless(id: PathBuf) -> Result<StoreId> {
|
pub fn new_baseless(id: PathBuf) -> Result<StoreId> {
|
||||||
if id.is_absolute() {
|
if id.is_absolute() {
|
||||||
Err(SEK::StoreIdLocalPartAbsoluteError.into_error())
|
Err(SEK::StoreIdLocalPartAbsoluteError.into_error())
|
||||||
|
|
Loading…
Reference in a new issue