fix: Made the vault file location more fault tolerant

This commit is contained in:
2025-09-12 13:42:51 -06:00
parent a1a210eb16
commit 69c7a083a2
2 changed files with 10 additions and 4 deletions
+3 -3
View File
@@ -27,8 +27,8 @@ use serde::{Deserialize, Serialize};
use serde_with::serde_as; use serde_with::serde_as;
use serde_with::{DisplayFromStr, skip_serializing_none}; use serde_with::{DisplayFromStr, skip_serializing_none};
use std::borrow::Cow; use std::borrow::Cow;
use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
use std::{env, fs};
use validator::{Validate, ValidationError}; use validator::{Validate, ValidationError};
#[skip_serializing_none] #[skip_serializing_none]
@@ -263,7 +263,7 @@ impl Config {
/// println!("loaded config: {:?}", config); /// println!("loaded config: {:?}", config);
/// ``` /// ```
pub fn load_config() -> Result<Config> { pub fn load_config() -> Result<Config> {
let xdg_path = std::env::var_os("XDG_CONFIG_HOME").map(PathBuf::from); let xdg_path = env::var_os("XDG_CONFIG_HOME").map(PathBuf::from);
let mut config: Config = if let Some(base) = xdg_path.as_ref() { let mut config: Config = if let Some(base) = xdg_path.as_ref() {
let app_dir = base.join("gman"); let app_dir = base.join("gman");
@@ -303,7 +303,7 @@ pub fn load_config() -> Result<Config> {
/// Returns the configuration file path that `confy` will use for this app. /// Returns the configuration file path that `confy` will use for this app.
pub fn get_config_file_path() -> Result<PathBuf> { pub fn get_config_file_path() -> Result<PathBuf> {
if let Some(base) = std::env::var_os("XDG_CONFIG_HOME").map(PathBuf::from) { if let Some(base) = env::var_os("XDG_CONFIG_HOME").map(PathBuf::from) {
let dir = base.join("gman"); let dir = base.join("gman");
let yml = dir.join("config.yml"); let yml = dir.join("config.yml");
let yaml = dir.join("config.yaml"); let yaml = dir.join("config.yaml");
+7 -1
View File
@@ -1,8 +1,8 @@
use anyhow::{Context, anyhow, bail}; use anyhow::{Context, anyhow, bail};
use secrecy::{ExposeSecret, SecretString}; use secrecy::{ExposeSecret, SecretString};
use std::collections::HashMap; use std::collections::HashMap;
use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::{env, fs};
use zeroize::Zeroize; use zeroize::Zeroize;
use crate::config::ProviderConfig; use crate::config::ProviderConfig;
@@ -197,6 +197,12 @@ impl SecretProvider for LocalProvider {
} }
fn default_vault_path() -> Result<PathBuf> { fn default_vault_path() -> Result<PathBuf> {
let xdg_path = env::var_os("XDG_CONFIG_HOME").map(PathBuf::from);
if let Some(xdg) = xdg_path {
return Ok(xdg.join("gman").join("vault.yml"));
}
confy::get_configuration_file_path("gman", "vault").with_context(|| "get config dir") confy::get_configuration_file_path("gman", "vault").with_context(|| "get config dir")
} }