From 7faa693d5c27bcfdbc791f498f16654f75d46cb9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 23 Nov 2015 19:15:26 +0100 Subject: [PATCH] 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. --- src/storage/backend.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/storage/backend.rs b/src/storage/backend.rs index 65c965e6..52d53076 100644 --- a/src/storage/backend.rs +++ b/src/storage/backend.rs @@ -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 { - 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)]