Skip to content

Commit c987094

Browse files
authored
feat(auth): Allow global config to be located in XDG directory (#2059)
If the global config file does not exist in the home directory, look in the following paths: - Linux: $XDG_CONFIG_HOME/sentry/sentrycli.ini and $HOME/.config/sentry/sentrycli.ini - Mac: $HOME/Library/Application Support/sentry/sentrycli.ini - Windows: {FOLDERID_RoamingAppData} This enables users to keep their home dir clean, adhering to standards such as XDG on linux. Fixes GH-1521
1 parent 0295c36 commit c987094

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/config.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use log::{debug, info, set_max_level, warn};
1414
use parking_lot::Mutex;
1515
use sentry::types::Dsn;
1616

17+
use crate::constants::CONFIG_INI_FILE_PATH;
1718
use crate::constants::DEFAULT_MAX_DIF_ITEM_SIZE;
1819
use crate::constants::DEFAULT_MAX_DIF_UPLOAD_SIZE;
1920
use crate::constants::{CONFIG_RC_FILE_NAME, DEFAULT_RETRIES, DEFAULT_URL};
@@ -526,12 +527,14 @@ impl Config {
526527
}
527528

528529
fn find_global_config_file() -> Result<PathBuf> {
529-
dirs::home_dir()
530+
let home_dir_file = dirs::home_dir().map(|p| p.join(CONFIG_RC_FILE_NAME));
531+
let config_dir_file = dirs::config_dir().map(|p| p.join(CONFIG_INI_FILE_PATH));
532+
home_dir_file
533+
.clone()
534+
.filter(|p| p.exists())
535+
.or(config_dir_file.filter(|p| p.exists()))
536+
.or(home_dir_file)
530537
.ok_or_else(|| format_err!("Could not find home dir"))
531-
.map(|mut path| {
532-
path.push(CONFIG_RC_FILE_NAME);
533-
path
534-
})
535538
}
536539

537540
fn find_project_config_file() -> Option<PathBuf> {

src/constants.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
1414
/// The name of the configuration file.
1515
pub const CONFIG_RC_FILE_NAME: &str = ".sentryclirc";
1616

17+
/// The relative path of the configuration file in dirs::config_dir()
18+
pub const CONFIG_INI_FILE_PATH: &str = "sentry/sentrycli.ini";
19+
1720
/// The release registry URL where the latest released version of sentry-cli can be found
1821
pub const RELEASE_REGISTRY_LATEST_URL: &str =
1922
"https://release-registry.services.sentry.io/apps/sentry-cli/latest";

0 commit comments

Comments
 (0)