blob: ee611b4b0e2eb898422a267a46453a84a47ff7fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
use crate::Result;
use std::{env, path::PathBuf};
/// Creates and returns the settings directory pointed to by `MULLVAD_SETTINGS_DIR`, or the default
/// one if that variable is unset.
pub fn settings_dir() -> Result<PathBuf> {
#[cfg(not(target_os = "windows"))]
{
crate::create_and_return(get_settings_dir, None)
}
#[cfg(target_os = "windows")]
{
crate::create_and_return(get_settings_dir, false)
}
}
fn get_settings_dir() -> Result<PathBuf> {
match env::var_os("MULLVAD_SETTINGS_DIR") {
Some(path) => Ok(PathBuf::from(path)),
None => get_default_settings_dir(),
}
}
pub fn get_default_settings_dir() -> Result<PathBuf> {
#[cfg(not(target_os = "android"))]
{
let dir;
#[cfg(unix)]
{
dir = Ok(PathBuf::from("/etc"));
}
#[cfg(windows)]
{
dir = crate::windows::get_system_service_appdata().map_err(|error| {
log::error!("Failed to obtain system app data path: {error}");
crate::Error::FindDirError
})
}
dir.map(|dir| dir.join(crate::PRODUCT_NAME))
}
#[cfg(target_os = "android")]
{
Ok(PathBuf::from(crate::APP_PATH))
}
}
|