Add Store::ensure_store_path_exists()

This commit is contained in:
Matthias Beyer 2015-12-28 11:25:07 +01:00
parent c97f4bab56
commit d20ace3e80

View file

@ -133,6 +133,8 @@ impl Store {
format!("{}/{}-{}.imag", self.storepath, file.owning_module_name, ids)
};
self.ensure_store_path_exists();
FSFile::create(&path).map(|mut fsfile| {
fsfile.write_all(&text.unwrap().clone().into_bytes()[..])
}).map_err(|writeerr| {
@ -140,6 +142,18 @@ impl Store {
}).and(Ok(true)).unwrap()
}
fn ensure_store_path_exists(&self) {
use std::fs::create_dir_all;
use std::process::exit;
create_dir_all(&self.storepath).unwrap_or_else(|e| {
error!("Could not create store: '{}'", self.storepath);
error!("Error : '{}'", e);
error!("Killing myself now");
exit(1);
})
}
pub fn load(&self, id: &FileID) -> Option<Rc<RefCell<File>>> {
debug!("Loading '{:?}'", id);
self.cache.borrow().get(id).cloned()