summaryrefslogtreecommitdiffstats
path: root/src/conf/default.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/conf/default.rs')
-rw-r--r--src/conf/default.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/conf/default.rs b/src/conf/default.rs
new file mode 100644
index 0000000..93a87e2
--- /dev/null
+++ b/src/conf/default.rs
@@ -0,0 +1,34 @@
+use {
+ include_dir::{Dir, include_dir},
+ std::{
+ fs,
+ io,
+ path::Path,
+ },
+};
+
+static DEFAULT_CONF_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/resources/default-conf");
+
+pub fn write_default_conf_in(dir: &Path) -> Result<(), io::Error> {
+ info!("writing default conf in {:?}", dir);
+ if dir.exists() {
+ if !dir.is_dir() {
+ return Err(io::Error::new(
+ io::ErrorKind::Other,
+ format!("{:?} isn't a directory", dir),
+ ));
+ }
+ } else {
+ fs::create_dir_all(dir)?;
+ }
+ for file in DEFAULT_CONF_DIR.files() {
+ let dest_path = dir.join(file.path());
+ if dest_path.exists() {
+ warn!("not overwriting {:?}", dest_path);
+ } else {
+ info!("writing file {:?}", file.path());
+ fs::write(dest_path, file.contents())?;
+ }
+ }
+ Ok(())
+}