From 315b2f19261c85f492c6634340f189f8fb58a1a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Th=C3=A9riault?= Date: Mon, 7 Oct 2019 21:18:34 -0400 Subject: [PATCH] Custom static files path in cdebug builds --- .env.example | 3 ++- .gitignore | 1 - src/setup.rs | 21 +++++++++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) 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 {