chore(config): use config from current directory instead of system configuration directory

This commit is contained in:
MedzikUser 2022-08-29 09:22:51 +02:00
parent 4e9ecc007c
commit 07a9eddede
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
5 changed files with 10 additions and 14 deletions

1
Cargo.lock generated
View File

@ -720,7 +720,6 @@ dependencies = [
"anyhow",
"axum",
"crypto-utils",
"dirs",
"hex",
"serde",
"sqlx",

View File

@ -6,3 +6,8 @@ members = [
"types",
]
resolver = "2"
[profile.release]
lto = true
opt-level = 'z'
codegen-units = 1

View File

@ -11,11 +11,9 @@ pub const DATABASE_FILE: &str = "homedisk.db";
#[tokio::main]
async fn main() {
// initialize logger
logger::init();
// parse config
let config = Config::parse().expect("parse config");
let config = Config::parse().expect("Failed to parse configuration file");
// open database connection
let db =

View File

@ -4,7 +4,7 @@ version = "0.0.0"
edition = "2021"
[features]
config = ["toml", "dirs"]
config = ["toml"]
database = ["crypto-utils", "hex", "sqlx"]
[dependencies]
@ -14,7 +14,6 @@ anyhow = "1.0.62"
serde = { version = "1.0.144", features = ["derive"] }
axum = { version = "0.5.15", optional = true }
toml = { version = "0.5.9", optional = true }
dirs = { version = "4.0.0", optional = true }
crypto-utils = { version = "0.4.0", features = ["sha"], optional = true }
hex = { version = "0.4.3", optional = true }
sqlx = { version = "0.6.1", features = ["sqlite"], optional = true }

View File

@ -46,15 +46,10 @@ impl Config {
/// let config = Config::parse().unwrap();
/// ```
pub fn parse() -> anyhow::Result<Config> {
// get path to the user's config directory
let sys_config_dir = dirs::config_dir().unwrap();
// path to the homedisk config file
let config_path = format!("{}/homedisk/config.toml", sys_config_dir.to_string_lossy());
let config = fs::read_to_string("config.toml")?;
// read file content to string
let config = fs::read_to_string(config_path)?;
let serialized = toml::from_str(&config)?;
// parse config and return it
Ok(toml::from_str(&config)?)
Ok(serialized)
}
}