From c97f4bab5682f71690f520234dfff0a0c2991ff0 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 28 Dec 2015 14:40:56 +0100 Subject: [PATCH] Add Store::remove(FileID) --- src/storage/mod.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 4905440b..f10f6dab 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -145,6 +145,23 @@ impl Store { self.cache.borrow().get(id).cloned() } + pub fn remove(&self, id: FileID) -> bool { + use std::fs::remove_file; + + self.cache + .borrow_mut() + .remove(&id) + .map(|file| { + let idstr : String = id.into(); + let path = format!("{}/{}-{}.imag", + self.storepath, + file.deref().borrow().owner_name(), + idstr); + remove_file(path).is_ok() + }) + .unwrap_or(false) + } + fn get_new_file_id(&self) -> FileID { use uuid::Uuid; let hash = FileHash::from(Uuid::new_v4().to_hyphenated_string());