diff options
| author | David Lönnhager <david.l@mullvad.net> | 2022-02-25 11:56:23 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2022-03-14 12:08:52 +0100 |
| commit | 6a704d32085e51e5eb8b76d3410bd70089b8dfc4 (patch) | |
| tree | 9f41706ef76801f2cb58548e9fe42654a313bec3 | |
| parent | f1ca2b65ef82f4450e1a9f1cfbde2956b8aeb37f (diff) | |
| download | mullvadvpn-6a704d32085e51e5eb8b76d3410bd70089b8dfc4.tar.xz mullvadvpn-6a704d32085e51e5eb8b76d3410bd70089b8dfc4.zip | |
Delete device cache in mullvad-setup
| -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)?; } |
