Skip to content

Commit

Permalink
fix: delete downloaded file on action timeout (#340)
Browse files Browse the repository at this point in the history
* fix: delete partially downloaded file when handling a timeout

* fix: error out instead of success response
  • Loading branch information
Devdutt Shenoi authored Apr 16, 2024
1 parent 500a578 commit 88805cf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion uplink/src/collector/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -221,7 +223,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 Err(Error::Timeout);
},
}
}

Expand Down

0 comments on commit 88805cf

Please sign in to comment.