diff --git a/src/storage/backend.rs b/src/storage/backend.rs index 0ded5b89..abb00bfe 100644 --- a/src/storage/backend.rs +++ b/src/storage/backend.rs @@ -14,7 +14,7 @@ use glob::Paths; use storage::file::File; use storage::file_id::*; -type BackendOperationResult = Result<(), StorageBackendError>; +pub type BackendOperationResult = Result<(), StorageBackendError>; pub struct StorageBackend { basepath: String, @@ -47,36 +47,29 @@ impl StorageBackend { } } - fn createEmpty(&self) -> Option { - self.new_file_handle().and_then(|(id, _)| Some(id)) + /* + * Write a file to disk. + * + * The file is moved to this function as the file won't be edited afterwards + */ + pub fn put_file(f: File) -> BackendOperationResult { } - fn createFile(&self) -> Option { - self.new_file_handle().and_then(|(id, h)| Some(File::from_handle(id, h))) + /* + * Update a file. We have the UUID and can find the file on FS with it and + * then replace its contents with the contents of the passed file object + */ + pub fn update_file(f: File) -> BackendOperationResult { } - fn writeFile(f: File) -> BackendOperationResult { - } - - fn createFileWithContent(content: String) -> BackendOperationResult { - } - - fn readFile(id: FileID) -> String { - } - - // TODO: Meta files are not covered yet - - fn new_file_handle(&self) -> Option<(FileID, FSFile)> { - use uuid::Uuid; - let uuid = Uuid::new_v4().to_hyphenated_string(); - let pathstr = self.basepath + uuid.as_str(); - let path = Path::new(&pathstr); - - if let Ok(f) = FSFile::create(path) { - Some((uuid, f)) - } else { - None - } + /* + * Find a file by its ID and return it if found. Return nothing if not + * found, of course. + * + * TODO: Needs refactoring, as there might be an error when reading from + * disk OR the id just does not exist. + */ + pub fn get_file_by_id(id: FileID) -> Option { } } diff --git a/src/storage/file.rs b/src/storage/file.rs index a8b142ad..c80d99ae 100644 --- a/src/storage/file.rs +++ b/src/storage/file.rs @@ -165,49 +165,29 @@ pub fn match_header_spec<'a>(spec: &'a FileHeaderSpec, data: &'a FileHeaderData) None } +/* + * Internal abstract view on a file. Does not exist on the FS and is just kept + * internally until it is written to disk. + */ pub struct File { header : FileHeaderData, data : String, id : FileID, - handle : Option, } -impl<'a> File { - - fn new(prs: &Parser, path: &String) -> Result - where HP: FileHeaderParser<'a> - { - File::read_file(path).and_then(|p| prs.read(p)) - .and_then(|(h, d)| - Ok(File { - header: h, - data: d, - id: from_path_string(path), - handle: None, - })) - } - - pub fn from_handle(id: FileID, f: FSFile) -> File { - use std::io::Read; - - let mut contents = String::new(); - f.read_to_string(&mut contents); +impl File { + pub fn new() -> File { File { header: FileHeaderData::Null, - data: contents, - id: id, - handle: Some(f) + data: String::from(""), + id: File::get_new_file_id(), } } - fn getID(&self) -> FileID { - self.id.clone() + fn get_new_file_id() -> FileID { + use uuid::Uuid; + Uuid::new_v4().to_hyphenated_string() } - - fn read_file(p: &String) -> Result { - Ok(String::from("")) - } - }