Move implementation to get a new file on the FS

Now we have a function which creates a new file on the FS and returns
the handle and the FileID object.
This commit is contained in:
Matthias Beyer 2015-11-23 19:15:26 +01:00
parent 48fd3e66f5
commit 7faa693d5c

View file

@ -5,6 +5,8 @@ use std::fmt::Result as FMTResult;
use std::path::Path;
use std::path::PathBuf;
use std::vec::Vec;
use std::fs::File as FSFile;
use std::io::Read;
use glob::glob;
use glob::Paths;
@ -46,17 +48,7 @@ impl StorageBackend {
}
fn createEmpty(&self) -> Option<FileID> {
use std::fs::File;
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) = File::create(path) {
Some(uuid)
} else {
None
}
self.new_file_handle().and_then(|(id, _)| Some(id))
}
fn createFile() -> File {
@ -73,6 +65,19 @@ impl StorageBackend {
// 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
}
}
}
#[derive(Debug)]