Page MenuHomeDevCentral

D3016.id7697.diff
No OneTemporary

D3016.id7697.diff

diff --git a/src/db.rs b/src/db.rs
--- a/src/db.rs
+++ b/src/db.rs
@@ -5,8 +5,10 @@
// License: BSD-2-Clause
// -------------------------------------------------------------
+use std::fs;
use std::fs::OpenOptions;
use std::io::Error as IOError;
+use std::io::ErrorKind;
use std::path::{Path, PathBuf};
use log::warn;
@@ -39,10 +41,17 @@
let path = self.get_initialized_path(site_name);
if !path.exists() {
- match touch(&path) {
- Ok(_) => true,
+ match ensure_parent_directory_exists(&path) {
+ Ok(_) => match touch(&path) {
+ Ok(_) => true,
+ Err(error) => {
+ warn!("Can't mark site {} as initialized: {:?}", site_name, error);
+
+ false
+ }
+ },
Err(error) => {
- warn!("Can't mark site {} as initialized: {:?}", site_name, error);
+ warn!("Can't create parent directory for {:?}: {:?}", &path, error);
false
}
@@ -66,6 +75,18 @@
options.open(path).map(|_| ())
}
+fn ensure_parent_directory_exists(path: &PathBuf) -> Result<(), IOError> {
+ let parent = path
+ .parent()
+ .ok_or_else(|| IOError::new(ErrorKind::InvalidInput, "Invalid path"))?;
+
+ if !parent.exists() {
+ fs::create_dir_all(parent)?;
+ }
+
+ Ok(())
+}
+
// -------------------------------------------------------------
// Tests
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 18, 22:19 (22 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2251351
Default Alt Text
D3016.id7697.diff (1 KB)

Event Timeline