Skip to content

Commit

Permalink
fix get config file
Browse files Browse the repository at this point in the history
  • Loading branch information
alvaro17f committed Aug 21, 2023
1 parent f503ec1 commit 8efc7aa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Wrestic is a backup tool built in Rust that provides a wrapper around Restic, a popular backup program. With Wrestic, you can easily configure and run backups of your files and directories, and take advantage of Restic's powerful features such as deduplication, encryption, and compression. Whether you need to back up your personal files or your organization's data, Wrestic can help you automate the process and ensure your data is safe and secure.

> ⚠️ by now, it only works with Backblaze B2
> ⚠️ currently only works with Backblaze B2
## TABLE OF CONTENTS[![](https://raw.githubusercontent.com/aregtech/areg-sdk/master/docs/img/pin.svg)](#table-of-contents)
- [WRESTIC](#wrestic)
Expand Down
27 changes: 24 additions & 3 deletions src/utils/get_config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::macros::anyhow::error;
use anyhow::{Context, Result};
use config::Config;

use crate::macros::anyhow::error;
use std::{fs, path::PathBuf};

#[derive(Debug, Clone)]
#[allow(dead_code)]
Expand All @@ -19,9 +19,30 @@ pub struct Settings {
}

pub fn get_config() -> Result<Vec<Settings>> {
fn find_config_file() -> Option<PathBuf> {
let home_dir = PathBuf::from("/home/");
let mut path = PathBuf::new();
for entry in fs::read_dir(home_dir).ok()? {
let entry = entry.ok()?;
let mut env_path = entry.path();
env_path.push(".config/wrestic/wrestic.toml");
if env_path.exists() {
path = env_path;
break;
}
}
if path.exists() {
Some(path)
} else {
None
}
}
let config = Config::builder()
.add_source(config::File::with_name(
"/home/alvaro17f/.config/wrestic/wrestic.toml",
find_config_file()
.context(error!("Failed to find config file"))?
.to_str()
.context(error!("Failed to convert config path to string"))?,
))
.build()?;

Expand Down

0 comments on commit 8efc7aa

Please sign in to comment.