diff options
| -rw-r--r-- | mullvad-daemon/src/device.rs | 15 | ||||
| -rw-r--r-- | mullvad-setup/src/main.rs | 4 |
2 files changed, 16 insertions, 3 deletions
diff --git a/mullvad-daemon/src/device.rs b/mullvad-daemon/src/device.rs index 4b98c5b414..c0dc1296fb 100644 --- a/mullvad-daemon/src/device.rs +++ b/mullvad-daemon/src/device.rs @@ -693,6 +693,7 @@ impl DeviceService { pub struct DeviceCacher { file: io::BufWriter<fs::File>, + path: std::path::PathBuf, } impl DeviceCacher { @@ -717,7 +718,7 @@ impl DeviceCacher { .write(true) .read(true) .create(true) - .open(path) + .open(&path) .await?; let device: Option<DeviceData> = if cache_exists { @@ -736,6 +737,7 @@ impl DeviceCacher { Ok(( DeviceCacher { file: io::BufWriter::new(file), + path, }, device, )) @@ -752,6 +754,17 @@ impl DeviceCacher { Ok(()) } + + pub async fn remove(self) -> Result<(), Error> { + let path = { + let DeviceCacher { path, file } = self; + let std_file = file.into_inner().into_std().await; + let _ = tokio::task::spawn_blocking(move || drop(std_file)).await; + path + }; + tokio::fs::remove_file(path).await?; + Ok(()) + } } #[derive(Clone)] diff --git a/mullvad-setup/src/main.rs b/mullvad-setup/src/main.rs index a5a4761454..e9289b115a 100644 --- a/mullvad-setup/src/main.rs +++ b/mullvad-setup/src/main.rs @@ -164,7 +164,7 @@ async fn reset_firewall() -> Result<(), Error> { async fn remove_device() -> Result<(), Error> { let (cache_path, settings_path) = get_paths()?; - let (mut cacher, data) = mullvad_daemon::device::DeviceCacher::new(&settings_path) + let (cacher, data) = mullvad_daemon::device::DeviceCacher::new(&settings_path) .await .map_err(Error::ReadDeviceCacheError)?; if let Some(device) = data { @@ -195,7 +195,7 @@ async fn remove_device() -> Result<(), Error> { .map_err(Error::RemoveDeviceError)?; cacher - .write(None) + .remove() .await .map_err(Error::WriteDeviceCacheError)?; } |
