Reset and restart implementation
This commit is contained in:
parent
e623b74139
commit
b8fa7c5696
2 changed files with 31 additions and 58 deletions
|
@ -14,7 +14,7 @@ use glob::Paths;
|
||||||
use storage::file::File;
|
use storage::file::File;
|
||||||
use storage::file_id::*;
|
use storage::file_id::*;
|
||||||
|
|
||||||
type BackendOperationResult = Result<(), StorageBackendError>;
|
pub type BackendOperationResult = Result<(), StorageBackendError>;
|
||||||
|
|
||||||
pub struct StorageBackend {
|
pub struct StorageBackend {
|
||||||
basepath: String,
|
basepath: String,
|
||||||
|
@ -47,36 +47,29 @@ impl StorageBackend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn createEmpty(&self) -> Option<FileID> {
|
/*
|
||||||
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<File> {
|
/*
|
||||||
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 {
|
/*
|
||||||
}
|
* Find a file by its ID and return it if found. Return nothing if not
|
||||||
|
* found, of course.
|
||||||
fn createFileWithContent(content: String) -> BackendOperationResult {
|
*
|
||||||
}
|
* TODO: Needs refactoring, as there might be an error when reading from
|
||||||
|
* disk OR the id just does not exist.
|
||||||
fn readFile(id: FileID) -> String {
|
*/
|
||||||
}
|
pub fn get_file_by_id(id: FileID) -> Option<File> {
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,49 +165,29 @@ pub fn match_header_spec<'a>(spec: &'a FileHeaderSpec, data: &'a FileHeaderData)
|
||||||
None
|
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 {
|
pub struct File {
|
||||||
header : FileHeaderData,
|
header : FileHeaderData,
|
||||||
data : String,
|
data : String,
|
||||||
id : FileID,
|
id : FileID,
|
||||||
handle : Option<FSFile>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> File {
|
impl File {
|
||||||
|
|
||||||
fn new<HP>(prs: &Parser<HP>, path: &String) -> Result<File, ParserError>
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
pub fn new() -> File {
|
||||||
File {
|
File {
|
||||||
header: FileHeaderData::Null,
|
header: FileHeaderData::Null,
|
||||||
data: contents,
|
data: String::from(""),
|
||||||
id: id,
|
id: File::get_new_file_id(),
|
||||||
handle: Some(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getID(&self) -> FileID {
|
fn get_new_file_id() -> FileID {
|
||||||
self.id.clone()
|
use uuid::Uuid;
|
||||||
|
Uuid::new_v4().to_hyphenated_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_file(p: &String) -> Result<String, ParserError> {
|
|
||||||
Ok(String::from(""))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue