Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3768096
D3016.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D3016.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 06:22 (8 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259604
Default Alt Text
D3016.diff (1 KB)
Attached To
Mode
D3016: Create initialized sites subdirectory
Attached
Detach File
Event Timeline
Log In to Comment