summaryrefslogtreecommitdiffhomepage
path: root/mullvad-paths
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2021-01-08 16:32:31 +0100
committerDavid Lönnhager <david.l@mullvad.net>2021-01-12 16:10:21 +0100
commit00885edcf042d4ae45eed26c2f5c2c67bc5de9ec (patch)
treec9dcf02bfc652d32ac90ecefb3dc452975699141 /mullvad-paths
parent12ca4a60bf3455132aed849ad8d5df87cd919d35 (diff)
downloadmullvadvpn-00885edcf042d4ae45eed26c2f5c2c67bc5de9ec.tar.xz
mullvadvpn-00885edcf042d4ae45eed26c2f5c2c67bc5de9ec.zip
Replace the old cache directory
Diffstat (limited to 'mullvad-paths')
-rw-r--r--mullvad-paths/src/cache.rs45
-rw-r--r--mullvad-paths/src/lib.rs2
2 files changed, 17 insertions, 30 deletions
diff --git a/mullvad-paths/src/cache.rs b/mullvad-paths/src/cache.rs
index 490fe9f702..8d9f4bea45 100644
--- a/mullvad-paths/src/cache.rs
+++ b/mullvad-paths/src/cache.rs
@@ -4,10 +4,14 @@ use std::{env, path::PathBuf};
/// Creates and returns the cache directory pointed to by `MULLVAD_CACHE_DIR`, or the default
/// one if that variable is unset.
pub fn cache_dir() -> Result<PathBuf> {
- crate::create_and_return(get_cache_dir, None)
+ #[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_cache_dir, permissions)
}
-fn get_cache_dir() -> Result<PathBuf> {
+pub fn get_cache_dir() -> Result<PathBuf> {
match env::var_os("MULLVAD_CACHE_DIR") {
Some(path) => Ok(PathBuf::from(path)),
None => get_default_cache_dir(),
@@ -20,39 +24,22 @@ pub fn get_default_cache_dir() -> Result<PathBuf> {
let dir;
#[cfg(target_os = "linux")]
{
- dir = Ok(PathBuf::from("/var/cache"))
+ dir = PathBuf::from("/var/cache").join(crate::PRODUCT_NAME);
+ }
+ #[cfg(windows)]
+ {
+ dir = crate::get_allusersprofile_dir()?
+ .join(crate::PRODUCT_NAME)
+ .join("cache");
}
- #[cfg(any(target_os = "macos", windows))]
+ #[cfg(target_os = "macos")]
{
- dir = dirs_next::cache_dir().ok_or_else(|| crate::Error::FindDirError)
+ dir = std::path::Path::new("/Library/Caches").join(crate::PRODUCT_NAME);
}
- dir.map(|dir| dir.join(crate::PRODUCT_NAME))
+ Ok(dir)
}
#[cfg(target_os = "android")]
{
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 03453e9adc..39cf486b52 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, get_user_cache_dir, user_cache_dir};
+pub use crate::cache::{cache_dir, get_cache_dir, get_default_cache_dir};
mod logs;
pub use crate::logs::{get_default_log_dir, get_log_dir, log_dir};