Merge branch 'path-to-id'
This commit is contained in:
commit
3664c59a5e
2 changed files with 61 additions and 4 deletions
|
@ -60,7 +60,11 @@ impl StorageBackend {
|
||||||
for entry in globlist {
|
for entry in globlist {
|
||||||
if let Ok(path) = entry {
|
if let Ok(path) = entry {
|
||||||
debug!(" - File: {:?}", path);
|
debug!(" - File: {:?}", path);
|
||||||
v.push(from_pathbuf(&path));
|
if let Ok(id) = from_pathbuf(&path) {
|
||||||
|
v.push(id);
|
||||||
|
} else {
|
||||||
|
error!("Cannot parse ID from path: {:?}", path);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Entry is not a path
|
// Entry is not a path
|
||||||
}
|
}
|
||||||
|
@ -77,6 +81,7 @@ impl StorageBackend {
|
||||||
glob(&self.prefix_of_files_for_module(m)[..]).and_then(|globlist| {
|
glob(&self.prefix_of_files_for_module(m)[..]).and_then(|globlist| {
|
||||||
let v = globlist.filter_map(Result::ok)
|
let v = globlist.filter_map(Result::ok)
|
||||||
.map(|pbuf| from_pathbuf(&pbuf))
|
.map(|pbuf| from_pathbuf(&pbuf))
|
||||||
|
.filter_map(Result::ok)
|
||||||
.collect::<Vec<FileID>>()
|
.collect::<Vec<FileID>>()
|
||||||
.into_iter();
|
.into_iter();
|
||||||
Ok(v)
|
Ok(v)
|
||||||
|
|
|
@ -1,16 +1,68 @@
|
||||||
|
use std::error::Error;
|
||||||
|
use std::fmt::{Debug, Display, Formatter};
|
||||||
|
use std::fmt;
|
||||||
|
use std::result::Result;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
pub type FileID = String;
|
pub type FileID = String;
|
||||||
|
|
||||||
pub fn from_path_string(s: &String) -> FileID {
|
pub struct FileIDError {
|
||||||
|
summary: String,
|
||||||
|
descrip: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FileIDError {
|
||||||
|
|
||||||
|
pub fn new(s: String, d: String) -> FileIDError {
|
||||||
|
FileIDError {
|
||||||
|
summary: s,
|
||||||
|
descrip: d,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Error for FileIDError {
|
||||||
|
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
&self.summary[..]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cause(&self) -> Option<&Error> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Debug for FileIDError {
|
||||||
|
|
||||||
|
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
|
||||||
|
write!(fmt, "FileIDError: '{}'\n{}", self.summary, self.descrip);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Display for FileIDError {
|
||||||
|
|
||||||
|
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
|
||||||
|
write!(fmt, "FileIDError: '{}'", self.summary);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type FileIDResult = Result<FileID, FileIDError>;
|
||||||
|
|
||||||
|
pub fn from_path_string(s: &String) -> FileIDResult {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_path(p: &Path) -> FileID {
|
pub fn from_path(p: &Path) -> FileIDResult {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_pathbuf(p: &PathBuf) -> FileID {
|
pub fn from_pathbuf(p: &PathBuf) -> FileIDResult {
|
||||||
from_path(p.as_path())
|
from_path(p.as_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue