summaryrefslogtreecommitdiffhomepage
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
parent12ca4a60bf3455132aed849ad8d5df87cd919d35 (diff)
downloadmullvadvpn-00885edcf042d4ae45eed26c2f5c2c67bc5de9ec.tar.xz
mullvadvpn-00885edcf042d4ae45eed26c2f5c2c67bc5de9ec.zip
Replace the old cache directory
-rw-r--r--mullvad-daemon/src/lib.rs3
-rw-r--r--mullvad-daemon/src/main.rs3
-rw-r--r--mullvad-jni/src/lib.rs1
-rw-r--r--mullvad-paths/src/cache.rs45
-rw-r--r--mullvad-paths/src/lib.rs2
-rw-r--r--mullvad-problem-report/src/lib.rs4
-rw-r--r--mullvad-problem-report/src/main.rs4
-rw-r--r--mullvad-setup/src/main.rs14
8 files changed, 29 insertions, 47 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index 00cbec6d36..93c02fff69 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -485,7 +485,6 @@ where
resource_dir: PathBuf,
settings_dir: PathBuf,
cache_dir: PathBuf,
- user_cache_dir: PathBuf,
event_listener: L,
command_channel: DaemonCommandChannel,
#[cfg(target_os = "android")] android_context: AndroidContext,
@@ -500,7 +499,7 @@ where
let mut rpc_runtime = mullvad_rpc::MullvadRpcRuntime::with_cache(
tokio::runtime::Handle::current(),
Some(&resource_dir),
- &user_cache_dir,
+ &cache_dir,
true,
move |address| {
let (result_tx, result_rx) = oneshot::channel();
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs
index bd91729af1..4e055183b9 100644
--- a/mullvad-daemon/src/main.rs
+++ b/mullvad-daemon/src/main.rs
@@ -123,8 +123,6 @@ async fn create_daemon(
.map_err(|e| e.display_chain_with_msg("Unable to get settings dir"))?;
let cache_dir = mullvad_paths::cache_dir()
.map_err(|e| e.display_chain_with_msg("Unable to get cache dir"))?;
- let user_cache_dir = mullvad_paths::user_cache_dir()
- .map_err(|e| e.display_chain_with_msg("Unable to get user cache dir"))?;
let command_channel = DaemonCommandChannel::new();
let event_listener = spawn_management_interface(command_channel.sender()).await?;
@@ -134,7 +132,6 @@ async fn create_daemon(
resource_dir,
settings_dir,
cache_dir,
- user_cache_dir,
event_listener,
command_channel,
)
diff --git a/mullvad-jni/src/lib.rs b/mullvad-jni/src/lib.rs
index 0b95495746..35fe78dd01 100644
--- a/mullvad-jni/src/lib.rs
+++ b/mullvad-jni/src/lib.rs
@@ -236,7 +236,6 @@ fn spawn_daemon(
Some(resource_dir.clone()),
resource_dir.clone(),
resource_dir,
- cache_dir.clone(),
cache_dir,
listener,
command_channel,
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};
diff --git a/mullvad-problem-report/src/lib.rs b/mullvad-problem-report/src/lib.rs
index f4ee9d73ae..9bd1fba185 100644
--- a/mullvad-problem-report/src/lib.rs
+++ b/mullvad-problem-report/src/lib.rs
@@ -256,7 +256,7 @@ pub fn send_problem_report(
user_email: &str,
user_message: &str,
report_path: &Path,
- user_cache_dir: &Path,
+ cache_dir: &Path,
) -> Result<(), Error> {
let report_content = normalize_newlines(
read_file_lossy(report_path, REPORT_MAX_SIZE).map_err(|source| {
@@ -279,7 +279,7 @@ pub fn send_problem_report(
.block_on(mullvad_rpc::MullvadRpcRuntime::with_cache(
runtime.handle().clone(),
None,
- user_cache_dir,
+ cache_dir,
false,
|_| Ok(()),
))
diff --git a/mullvad-problem-report/src/main.rs b/mullvad-problem-report/src/main.rs
index 4f0dfb0265..9a6189a610 100644
--- a/mullvad-problem-report/src/main.rs
+++ b/mullvad-problem-report/src/main.rs
@@ -113,8 +113,8 @@ fn run() -> Result<(), Error> {
let report_path = Path::new(send_matches.value_of_os("report").unwrap());
let user_email = send_matches.value_of("email").unwrap_or("");
let user_message = send_matches.value_of("message").unwrap_or("");
- let user_cache_dir = mullvad_paths::get_user_cache_dir()?;
- send_problem_report(user_email, user_message, report_path, &user_cache_dir)
+ let cache_dir = mullvad_paths::get_cache_dir()?;
+ send_problem_report(user_email, user_message, report_path, &cache_dir)
} else {
unreachable!("No sub command given");
}
diff --git a/mullvad-setup/src/main.rs b/mullvad-setup/src/main.rs
index c5ed2d38f0..0e9c104db1 100644
--- a/mullvad-setup/src/main.rs
+++ b/mullvad-setup/src/main.rs
@@ -152,12 +152,12 @@ async fn reset_firewall() -> Result<(), Error> {
}
async fn clear_history() -> Result<(), Error> {
- let (user_cache_path, settings_path) = get_paths()?;
+ let (cache_path, settings_path) = get_paths()?;
let mut rpc_runtime = MullvadRpcRuntime::with_cache(
tokio::runtime::Handle::current(),
None,
- &user_cache_path,
+ &cache_path,
false,
|_| Ok(()),
)
@@ -165,7 +165,7 @@ async fn clear_history() -> Result<(), Error> {
.map_err(Error::RpcInitializationError)?;
let mut account_history = account_history::AccountHistory::new(
- &user_cache_path,
+ &cache_path,
&settings_path,
rpc_runtime.mullvad_rest_handle(),
)
@@ -180,15 +180,15 @@ async fn clear_history() -> Result<(), Error> {
#[cfg(not(windows))]
fn get_paths() -> Result<(PathBuf, PathBuf), Error> {
- let user_cache_path = mullvad_paths::user_cache_dir().map_err(Error::CachePathError)?;
+ let cache_path = mullvad_paths::cache_dir().map_err(Error::CachePathError)?;
let settings_path = mullvad_paths::settings_dir().map_err(Error::SettingsPathError)?;
- Ok((user_cache_path, settings_path))
+ Ok((cache_path, settings_path))
}
#[cfg(windows)]
fn get_paths() -> Result<(PathBuf, PathBuf), Error> {
- let user_cache_path = mullvad_paths::user_cache_dir().map_err(Error::CachePathError)?;
+ let cache_path = mullvad_paths::cache_dir().map_err(Error::CachePathError)?;
let settings_path =
daemon_paths::get_mullvad_daemon_settings_path().map_err(Error::SettingsPathError)?;
- Ok((user_cache_path, settings_path))
+ Ok((cache_path, settings_path))
}