From 8507624f1a1da393b6210ff3a7ee07e6727c7885 Mon Sep 17 00:00:00 2001 From: Devdutt Shenoi Date: Tue, 16 Apr 2024 22:27:18 +0530 Subject: [PATCH 1/2] fix: delete partially downloaded file when handling a timeout --- uplink/src/collector/downloader.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/uplink/src/collector/downloader.rs b/uplink/src/collector/downloader.rs index 893e94ec..81c8a916 100644 --- a/uplink/src/collector/downloader.rs +++ b/uplink/src/collector/downloader.rs @@ -221,7 +221,13 @@ impl FileDownloader { // NOTE: if download has timedout don't do anything, else ensure errors are forwarded after three retries o = timeout_at(deadline, self.continuous_retry(state)) => match o { Ok(r) => r?, - Err(_) => error!("Last download has timedout"), + Err(_) => { + // unwrap is safe because download_path is expected to be Some + _ = remove_file(state.current.meta.download_path.as_ref().unwrap()); + error!("Last download has timedout; file deleted"); + + return Ok(()); + }, } } From 45b745d7a48810f5c50df7bfd1ef1df823985c2a Mon Sep 17 00:00:00 2001 From: Devdutt Shenoi Date: Tue, 16 Apr 2024 23:14:18 +0530 Subject: [PATCH 2/2] fix: error out instead of success response --- uplink/src/collector/downloader.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/uplink/src/collector/downloader.rs b/uplink/src/collector/downloader.rs index 81c8a916..ce5bbe38 100644 --- a/uplink/src/collector/downloader.rs +++ b/uplink/src/collector/downloader.rs @@ -93,6 +93,8 @@ pub enum Error { BadSave, #[error("Save file doesn't exist")] NoSave, + #[error("Download timedout")] + Timeout, } /// This struct contains the necessary components to download and store file as notified by a download file @@ -226,7 +228,7 @@ impl FileDownloader { _ = remove_file(state.current.meta.download_path.as_ref().unwrap()); error!("Last download has timedout; file deleted"); - return Ok(()); + return Err(Error::Timeout); }, } }