Skip to main content

squigit_storage/
paths.rs

1// Copyright 2026 a7mddra
2// SPDX-License-Identifier: Apache-2.0
3
4use std::path::PathBuf;
5
6const CONFIG_DIR_ENV: &str = "SQUIGIT_CONFIG_DIR";
7
8#[cfg(target_os = "linux")]
9const APP_DIR_NAME: &str = "squigit";
10
11#[cfg(not(target_os = "linux"))]
12const APP_DIR_NAME: &str = "Squigit";
13
14/// Resolve Squigit's application config root.
15///
16/// `SQUIGIT_CONFIG_DIR` overrides the OS default with an exact application root. This is used by
17/// isolated tooling that must not read or write the installed application's profile data.
18pub fn base_config_dir() -> Option<PathBuf> {
19    resolve_base_config_dir(
20        std::env::var_os(CONFIG_DIR_ENV).map(PathBuf::from),
21        dirs::config_dir(),
22    )
23}
24
25fn resolve_base_config_dir(
26    override_dir: Option<PathBuf>,
27    system_config_dir: Option<PathBuf>,
28) -> Option<PathBuf> {
29    override_dir
30        .filter(|path| !path.as_os_str().is_empty())
31        .or_else(|| system_config_dir.map(|path| path.join(APP_DIR_NAME)))
32}