diff --git a/.env.example b/.env.example index a9d5467..fbaed61 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ -DATABASE_URL=database.db +DATABASE_URL=target/database.db +FILES_DIR=target/static/ diff --git a/.gitignore b/.gitignore index 38f44b2..f3e12a7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ target/ # User specific files .env -**/*.db **/*.log # JetBrains settings diff --git a/src/setup.rs b/src/setup.rs index e2f1181..a80e9aa 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -1,4 +1,4 @@ -//! Functions used for the initial setup +//! Utilities used during the initial setup use crate::Pool; @@ -11,6 +11,8 @@ use std::path::PathBuf; use dotenv; #[cfg(debug_assertions)] use std::env; +#[cfg(debug_assertions)] +use std::str::FromStr; /// Returns a path to the directory storing application data pub fn get_data_dir() -> PathBuf { @@ -56,9 +58,20 @@ impl Default for Config { }; let pool_size = num_cpus::get() as u32 / 2; let files_dir = { - let mut path = get_data_dir(); - path.push("data"); - path + cfg_if! { + if #[cfg(debug_assertions)] { + let cargo_manifest_dir = env!("CARGO_MANIFEST_DIR"); + let mut path = PathBuf::from_str(cargo_manifest_dir) + .expect("Can't convert cargo manifest dir to path"); + let files_dir = env::var("FILES_DIR").expect("Can't parse FILES_DIR environment variable."); + path.push(&files_dir); + path + } else { + let mut path = get_data_dir(); + path.push("data"); + path + } + } }; Config {