diff options
| author | David Lönnhager <david.l@mullvad.net> | 2025-03-04 10:10:43 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2025-03-05 23:32:55 +0100 |
| commit | 753f73c7aa6e65f87fed312c1cf687c43d19a6c9 (patch) | |
| tree | 6dfa72504c49020870ffef3831b8457c3dbcbdf4 | |
| parent | 9c5ed68434cd10c75fdbb3788accf86f54376b22 (diff) | |
| download | mullvadvpn-753f73c7aa6e65f87fed312c1cf687c43d19a6c9.tar.xz mullvadvpn-753f73c7aa6e65f87fed312c1cf687c43d19a6c9.zip | |
Abort download task when begin_download is incorrectly called twice
| -rw-r--r-- | installer-downloader/src/controller.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/installer-downloader/src/controller.rs b/installer-downloader/src/controller.rs index 94c15de36d..7b6abce60c 100644 --- a/installer-downloader/src/controller.rs +++ b/installer-downloader/src/controller.rs @@ -323,9 +323,7 @@ impl<D: AppDelegate + 'static, A: From<UiAppDownloaderParameters<D>> + AppDownlo } async fn begin_download(&mut self) { - if self.active_download.take().is_some() { - log::debug!("Interrupting ongoing download"); - } + self.cancel_download().await; let Some(version_info) = self.version_info.clone() else { log::error!("Attempted 'begin download' before having version info"); return; @@ -410,10 +408,7 @@ impl<D: AppDelegate + 'static, A: From<UiAppDownloaderParameters<D>> + AppDownlo } async fn cancel(&mut self) { - if let Some(active_download) = self.active_download.take() { - active_download.abort(); - let _ = active_download.await; - } + self.cancel_download().await; let Some(version_info) = self.version_info.as_ref() else { log::error!("Attempted 'cancel' before having version info"); @@ -448,6 +443,14 @@ impl<D: AppDelegate + 'static, A: From<UiAppDownloaderParameters<D>> + AppDownlo self_.clear_download_progress(); }); } + + async fn cancel_download(&mut self) { + if let Some(active_download) = self.active_download.take() { + log::debug!("Interrupting ongoing download"); + active_download.abort(); + let _ = active_download.await; + } + } } /// Select a mirror to download from |
