From 8507624f1a1da393b6210ff3a7ee07e6727c7885 Mon Sep 17 00:00:00 2001 From: Devdutt Shenoi Date: Tue, 16 Apr 2024 22:27:18 +0530 Subject: [PATCH] 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 893e94ec9..81c8a9169 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(()); + }, } }