Fix silent corruption error
- When the server terminates a connection before the download is complete, the error wasn't noticed - Fixed error where the tokio receiver was dropped before all transmitters. This caused a panic when transmitters tried to send status udates. - Fixed error message still containing file path
This commit is contained in:
parent
a6e408a5e1
commit
a933c57396
@ -207,6 +207,10 @@ pub async fn download_feedback_chunks(url: &str, into_file: &str, rep: DlReporte
|
||||
if buff.len() > 0 {
|
||||
ofile.write_all(&buff).await?;
|
||||
}
|
||||
|
||||
if curr_progress != content_length {
|
||||
return Err(DlError::HttpNoData.into());
|
||||
}
|
||||
|
||||
// Ensure that IO is completed
|
||||
//ofile.flush().await?;
|
||||
@ -291,7 +295,7 @@ pub async fn download_feedback_multi(url: &str, into_file: &str, rep: DlReporter
|
||||
|
||||
let mut t_last = t_start.clone();
|
||||
|
||||
joiners.push(tokio::task::spawn(async move {
|
||||
let manager_handle = tokio::task::spawn(async move {
|
||||
|
||||
let rep = rep_task;
|
||||
//let mut dl_speeds = vec![0.0_f32; conn_count as usize];
|
||||
@ -357,8 +361,7 @@ pub async fn download_feedback_multi(url: &str, into_file: &str, rep: DlReporter
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
let mut joiners: FuturesUnordered<_> = joiners.into_iter().collect();
|
||||
@ -374,12 +377,16 @@ pub async fn download_feedback_multi(url: &str, into_file: &str, rep: DlReporter
|
||||
handle.abort();
|
||||
}
|
||||
|
||||
manager_handle.abort();
|
||||
|
||||
tokio::fs::remove_file(&into_file).await?;
|
||||
|
||||
return Err(e.into());
|
||||
}
|
||||
}
|
||||
|
||||
manager_handle.await?;
|
||||
|
||||
// Remove the additional byte at the file end
|
||||
let ofile = tokio::fs::OpenOptions::new()
|
||||
.create(false)
|
||||
|
||||
@ -9,6 +9,7 @@ pub type ResBE<T> = Result<T, Box<dyn Error>>;
|
||||
pub enum DlError {
|
||||
BadHttpStatus,
|
||||
ContentLengthUnknown,
|
||||
HttpNoData,
|
||||
Other(String)
|
||||
}
|
||||
|
||||
@ -20,6 +21,7 @@ impl Display for DlError {
|
||||
match self {
|
||||
DlError::BadHttpStatus => write!(f, "Bad http response status"),
|
||||
DlError::ContentLengthUnknown => write!(f, "Content-Length is unknown"),
|
||||
DlError::HttpNoData => write!(f, "Http server sent no more data"),
|
||||
DlError::Other(s) => write!(f, "Unknown download error: '{}'", s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,7 +266,7 @@ async fn download_multiple(urls: Vec<String>, outdir: &str, file_count: i32, con
|
||||
if conn_count == 1 {
|
||||
if let Err(_e) = download::download_feedback(&url, &into_file, rep.clone(), Some(filesize)).await {
|
||||
rep.send(DlStatus::DoneErr {
|
||||
filename: into_file.to_string()
|
||||
filename: file_name.to_string()
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@ -280,7 +280,7 @@ async fn download_multiple(urls: Vec<String>, outdir: &str, file_count: i32, con
|
||||
|
||||
if let Err(_e) = download::download_feedback_multi(&url, &into_file, rep.clone(), conn_count, Some(filesize)).await {
|
||||
rep.send(DlStatus::DoneErr {
|
||||
filename: into_file.to_string()
|
||||
filename: file_name.to_string()
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user