summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-04-28 17:37:46 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-04-28 17:37:46 -0300
commite4cb19e01dbf9ef620037a418cfa56a6ed391e2b (patch)
tree5c051450519ec6b2f91dfbde03552c704aa2145a
parent14177d8368a97779b13d20ec89c8c74869308426 (diff)
parent2a5289fc83dc833c7aabc423b382fbb758e0a6be (diff)
downloadmullvadvpn-e4cb19e01dbf9ef620037a418cfa56a6ed391e2b.tar.xz
mullvadvpn-e4cb19e01dbf9ef620037a418cfa56a6ed391e2b.zip
Merge branch 'move-account-history-to-settings-dir'
-rw-r--r--CHANGELOG.md2
-rw-r--r--mullvad-daemon/src/account_history.rs31
-rw-r--r--mullvad-daemon/src/lib.rs1
3 files changed, 33 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 735c14744c..eb2a45fe51 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,8 @@ Line wrap the file at 100 chars. Th
### Changed
- Downgrade to Electron 7 due to issues with tray icon in Electron 8.
- Use rustls instead of OpenSSL for TLS encryption to the API and GeoIP location service.
+- Move location of the account data (including the WireGuard keys), so that it isn't lost when the
+ system cache is cleaned.
#### Windows
- When required, attempt to enable IPv6 for network adapters instead of failing.
diff --git a/mullvad-daemon/src/account_history.rs b/mullvad-daemon/src/account_history.rs
index 56ebc6dc17..1bd74a052a 100644
--- a/mullvad-daemon/src/account_history.rs
+++ b/mullvad-daemon/src/account_history.rs
@@ -46,9 +46,12 @@ pub struct AccountHistory {
impl AccountHistory {
pub fn new(
cache_dir: &Path,
+ settings_dir: &Path,
rpc_handle: MullvadRestHandle,
tokio_remote: Remote,
) -> Result<AccountHistory> {
+ Self::migrate_from_old_file_location(cache_dir, settings_dir);
+
let mut options = fs::OpenOptions::new();
#[cfg(unix)]
{
@@ -61,7 +64,7 @@ impl AccountHistory {
// a share mode of zero ensures exclusive access to the file to *this* process
options.share_mode(0);
}
- let path = cache_dir.join(ACCOUNT_HISTORY_FILE);
+ let path = settings_dir.join(ACCOUNT_HISTORY_FILE);
log::info!("Opening account history file in {}", path.display());
let mut reader = options
.write(true)
@@ -100,6 +103,32 @@ impl AccountHistory {
Ok(history)
}
+ fn migrate_from_old_file_location(old_dir: &Path, new_dir: &Path) {
+ let old_path = old_dir.join(ACCOUNT_HISTORY_FILE);
+
+ if old_path.exists() {
+ let new_path = new_dir.join(ACCOUNT_HISTORY_FILE);
+
+ if new_path.exists() {
+ if let Err(error) = fs::remove_file(old_path) {
+ log::warn!(
+ "{}",
+ error.display_chain_with_msg("Failed to remove old account history file")
+ );
+ }
+ } else {
+ if let Err(error) = fs::rename(old_path, new_path) {
+ log::error!(
+ "{}",
+ error.display_chain_with_msg(
+ "Failed to migrate account history file location"
+ )
+ );
+ }
+ }
+ }
+ }
+
fn try_old_format(reader: &mut io::BufReader<fs::File>) -> Result<Vec<AccountToken>> {
#[derive(Deserialize)]
struct OldFormat {
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index f39d6a5a79..0b5e6eaf6c 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -505,6 +505,7 @@ where
let account_history = account_history::AccountHistory::new(
&cache_dir,
+ &settings_dir,
rpc_handle.clone(),
core_handle.remote.clone(),
)