summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-04-15 21:49:53 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-04-22 13:46:50 +0000
commitff43c691b30a4e597e5e4103d1e6a3dae7b67698 (patch)
tree5da435f5058fb2021df4cf9a4d4f69421f1fdb4c
parent84614a217a80a5c5fbf7b96d442eb29a85af79d2 (diff)
downloadmullvadvpn-ff43c691b30a4e597e5e4103d1e6a3dae7b67698.tar.xz
mullvadvpn-ff43c691b30a4e597e5e4103d1e6a3dae7b67698.zip
Move Windows migration into `SettingsPersister`
-rw-r--r--mullvad-daemon/src/settings.rs54
1 files changed, 27 insertions, 27 deletions
diff --git a/mullvad-daemon/src/settings.rs b/mullvad-daemon/src/settings.rs
index c6fa901288..18a61ec690 100644
--- a/mullvad-daemon/src/settings.rs
+++ b/mullvad-daemon/src/settings.rs
@@ -28,10 +28,7 @@ impl SettingsPersister {
}
#[cfg(windows)]
Err(SettingsError::ReadError(ref _path, ref e)) if e.kind() == ErrorKind::NotFound => {
- info!(
- "No settings file found. Attempting migration from Windows Update backup location"
- );
- if migrate_after_windows_update() {
+ if Self::migrate_after_windows_update() {
match Settings::load() {
Ok(settings) => {
info!("Successfully loaded migrated settings");
@@ -56,6 +53,32 @@ impl SettingsPersister {
SettingsPersister { settings }
}
+ #[cfg(windows)]
+ fn migrate_after_windows_update() -> bool {
+ info!("No settings file found. Attempting migration from Windows Update backup location");
+
+ match unsafe {
+ ffi::WinUtil_MigrateAfterWindowsUpdate(Some(log_sink), b"Settings migrator\0".as_ptr())
+ } {
+ ffi::WinUtilMigrationStatus::Success => {
+ info!("Migration completed successfully");
+ true
+ }
+ ffi::WinUtilMigrationStatus::Aborted => {
+ error!("Migration was aborted to avoid overwriting current settings");
+ false
+ }
+ ffi::WinUtilMigrationStatus::NothingToMigrate => {
+ info!("Could not migrate settings - no backup present");
+ false
+ }
+ ffi::WinUtilMigrationStatus::Failed | _ => {
+ error!("Migration failed");
+ false
+ }
+ }
+ }
+
pub fn to_settings(&self) -> Settings {
self.settings.clone()
}
@@ -75,29 +98,6 @@ impl DerefMut for SettingsPersister {
}
}
-#[cfg(windows)]
-fn migrate_after_windows_update() -> bool {
- match unsafe {
- ffi::WinUtil_MigrateAfterWindowsUpdate(Some(log_sink), b"Settings migrator\0".as_ptr())
- } {
- ffi::WinUtilMigrationStatus::Success => {
- info!("Migration completed successfully");
- true
- }
- ffi::WinUtilMigrationStatus::Aborted => {
- error!("Migration was aborted to avoid overwriting current settings");
- false
- }
- ffi::WinUtilMigrationStatus::NothingToMigrate => {
- info!("Could not migrate settings - no backup present");
- false
- }
- ffi::WinUtilMigrationStatus::Failed | _ => {
- error!("Migration failed");
- false
- }
- }
-}
#[cfg(windows)]
mod ffi {