summaryrefslogtreecommitdiffhomepage
path: root/mullvad-paths
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-12-02 17:36:39 +0100
committerDavid Lönnhager <david.l@mullvad.net>2021-01-04 16:50:18 +0100
commit29260429f5cdf04ef4e51a42a4abd11f5e2e03b7 (patch)
tree35db7806efabbf85c79cc919dc2fea07f30578ff /mullvad-paths
parent1680065e267b84f1443317ae942cd0c609e86b14 (diff)
downloadmullvadvpn-29260429f5cdf04ef4e51a42a4abd11f5e2e03b7.tar.xz
mullvadvpn-29260429f5cdf04ef4e51a42a4abd11f5e2e03b7.zip
Always prefer the last used API address
Diffstat (limited to 'mullvad-paths')
-rw-r--r--mullvad-paths/src/cache.rs23
-rw-r--r--mullvad-paths/src/lib.rs2
2 files changed, 24 insertions, 1 deletions
diff --git a/mullvad-paths/src/cache.rs b/mullvad-paths/src/cache.rs
index 35b99738f0..490fe9f702 100644
--- a/mullvad-paths/src/cache.rs
+++ b/mullvad-paths/src/cache.rs
@@ -33,3 +33,26 @@ pub fn get_default_cache_dir() -> Result<PathBuf> {
Ok(std::path::Path::new(crate::APP_PATH).join("cache"))
}
}
+
+/// Creates and returns a cache directory that is readable by all users.
+pub fn user_cache_dir() -> Result<PathBuf> {
+ #[cfg(not(target_os = "macos"))]
+ let permissions = None;
+ #[cfg(target_os = "macos")]
+ let permissions = Some(std::os::unix::fs::PermissionsExt::from_mode(0o755));
+ crate::create_and_return(get_user_cache_dir, permissions)
+}
+
+pub fn get_user_cache_dir() -> Result<PathBuf> {
+ #[cfg(windows)]
+ {
+ let dir = crate::get_allusersprofile_dir();
+ dir.map(|dir| dir.join(crate::PRODUCT_NAME))
+ }
+ #[cfg(target_os = "macos")]
+ {
+ Ok(std::path::Path::new("/Library/Caches").join(crate::PRODUCT_NAME))
+ }
+ #[cfg(not(any(target_os = "macos", windows)))]
+ get_cache_dir()
+}
diff --git a/mullvad-paths/src/lib.rs b/mullvad-paths/src/lib.rs
index 7b06c9937d..03453e9adc 100644
--- a/mullvad-paths/src/lib.rs
+++ b/mullvad-paths/src/lib.rs
@@ -56,7 +56,7 @@ fn create_and_return(
}
mod cache;
-pub use crate::cache::{cache_dir, get_default_cache_dir};
+pub use crate::cache::{cache_dir, get_default_cache_dir, get_user_cache_dir, user_cache_dir};
mod logs;
pub use crate::logs::{get_default_log_dir, get_log_dir, log_dir};