From 8b4cab1e691f46c0c0cbbcae8dc0b4e033114706 Mon Sep 17 00:00:00 2001 From: sigoden Date: Fri, 3 Nov 2023 20:58:53 +0800 Subject: [PATCH] fix: auto delete half-uploaded files (#280) --- src/server.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/server.rs b/src/server.rs index 0cd0989..85cbce1 100644 --- a/src/server.rs +++ b/src/server.rs @@ -427,7 +427,12 @@ impl Server { 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; Ok(())