Merge branch 'abstract-fileid'
This commit is contained in:
commit
37bf18df7f
5 changed files with 104 additions and 24 deletions
|
@ -51,7 +51,7 @@ pub fn remove_command(module: &Module, env: CommandEnv) -> CommandResult {
|
|||
debug!("Remove by id: {}", id);
|
||||
|
||||
let parser = Parser::new(JsonHeaderParser::new(None));
|
||||
let file = env.bk.get_file_by_id(module, &id, &parser).unwrap();
|
||||
let file = env.bk.get_file_by_id(module, &id.into(), &parser).unwrap();
|
||||
debug!("Remove file : {:?}", file);
|
||||
|
||||
if let Err(e) = env.bk.remove_file(module, file, checked) {
|
||||
|
|
|
@ -60,11 +60,7 @@ impl StorageBackend {
|
|||
for entry in globlist {
|
||||
if let Ok(path) = entry {
|
||||
debug!(" - File: {:?}", path);
|
||||
if let Ok(id) = from_pathbuf(&path) {
|
||||
v.push(id);
|
||||
} else {
|
||||
error!("Cannot parse ID from path: {:?}", path);
|
||||
}
|
||||
v.push(FileID::from(&path));
|
||||
} else {
|
||||
// Entry is not a path
|
||||
}
|
||||
|
@ -80,8 +76,7 @@ impl StorageBackend {
|
|||
{
|
||||
glob(&self.prefix_of_files_for_module(m)[..]).and_then(|globlist| {
|
||||
let v = globlist.filter_map(Result::ok)
|
||||
.map(|pbuf| from_pathbuf(&pbuf))
|
||||
.filter_map(Result::ok)
|
||||
.map(|pbuf| FileID::from(&pbuf))
|
||||
.collect::<Vec<FileID>>()
|
||||
.into_iter();
|
||||
Ok(v)
|
||||
|
@ -233,7 +228,8 @@ impl StorageBackend {
|
|||
debug!(" basepath: '{}'", self.basepath);
|
||||
debug!(" storepath: '{}'", self.storepath);
|
||||
debug!(" id : '{}'", id);
|
||||
self.prefix_of_files_for_module(owner) + "-" + &id[..] + ".imag"
|
||||
let idstr : String = id.into();
|
||||
self.prefix_of_files_for_module(owner) + "-" + &idstr[..] + ".imag"
|
||||
}
|
||||
|
||||
fn prefix_of_files_for_module(&self, m: &Module) -> String {
|
||||
|
|
|
@ -291,7 +291,7 @@ impl<'a> File<'a> {
|
|||
|
||||
fn get_new_file_id() -> FileID {
|
||||
use uuid::Uuid;
|
||||
Uuid::new_v4().to_hyphenated_string()
|
||||
FileID::new(FileIDType::UUID, Uuid::new_v4().to_hyphenated_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,102 @@ use std::fmt::{Debug, Display, Formatter};
|
|||
use std::fmt;
|
||||
use std::result::Result;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::convert::From;
|
||||
use std::convert::Into;
|
||||
|
||||
pub type FileID = String;
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone)]
|
||||
// #[derive(Display)]
|
||||
pub enum FileIDType {
|
||||
UUID,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct FileID {
|
||||
id: Option<String>,
|
||||
id_type: FileIDType,
|
||||
}
|
||||
|
||||
impl FileID {
|
||||
|
||||
pub fn new(id_type: FileIDType, id: String) -> FileID {
|
||||
FileID {
|
||||
id: Some(id),
|
||||
id_type: id_type,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_valid(&self) -> bool {
|
||||
self.id.is_some()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Debug for FileID {
|
||||
|
||||
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
|
||||
write!(fmt, "FileID[{:?}]: {:?}",
|
||||
self.id_type,
|
||||
self.id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Display for FileID {
|
||||
|
||||
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
|
||||
write!(fmt, "FileID[{:?}]: {:?}",
|
||||
self.id_type,
|
||||
self.id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Into<String> for FileID {
|
||||
|
||||
fn into(self) -> String {
|
||||
if let Some(id) = self.id {
|
||||
id.clone()
|
||||
} else {
|
||||
String::from("INVALID")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl From<String> for FileID {
|
||||
|
||||
fn from(s: String) -> FileID {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl<'a> From<&'a String> for FileID {
|
||||
|
||||
fn from(s: &'a String) -> FileID {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl From<PathBuf> for FileID {
|
||||
|
||||
fn from(s: PathBuf) -> FileID {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl<'a> From<&'a PathBuf> for FileID {
|
||||
|
||||
fn from(s: &'a PathBuf) -> FileID {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct FileIDError {
|
||||
summary: String,
|
||||
|
@ -54,15 +148,3 @@ impl<'a> Display for FileIDError {
|
|||
|
||||
pub type FileIDResult = Result<FileID, FileIDError>;
|
||||
|
||||
pub fn from_path_string(s: &String) -> FileIDResult {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn from_path(p: &Path) -> FileIDResult {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn from_pathbuf(p: &PathBuf) -> FileIDResult {
|
||||
from_path(p.as_path())
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,9 @@ impl FilePrinter for TablePrinter {
|
|||
i += 1;
|
||||
let cell_i = Cell::new(&format!("{}", i)[..]);
|
||||
let cell_o = Cell::new(&format!("{}", file.owner().name())[..]);
|
||||
let cell_id = Cell::new(&file.id()[..]);
|
||||
|
||||
let id : String = file.id().into();
|
||||
let cell_id = Cell::new(&id[..]);
|
||||
let row = Row::new(vec![cell_i, cell_o, cell_id]);
|
||||
tab.add_row(row);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue