fix: auto delete half-uploaded files (#280)

This commit is contained in:
sigoden 2023-11-03 20:58:53 +08:00 committed by GitHub
parent 70300b133c
commit 8b4cab1e69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -427,7 +427,12 @@ impl Server {
futures::pin_mut!(body_reader); futures::pin_mut!(body_reader);
io::copy(&mut body_reader, &mut file).await?; let ret = io::copy(&mut body_reader, &mut file).await;
if ret.is_err() {
tokio::fs::remove_file(&path).await?;
ret?;
}
*res.status_mut() = StatusCode::CREATED; *res.status_mut() = StatusCode::CREATED;
Ok(()) Ok(())