From 8599c1adbf55b4b2e524b8c17b53bd006f9a19eb Mon Sep 17 00:00:00 2001 From: Lynn Liu Date: Fri, 22 Sep 2023 10:20:12 -0700 Subject: [PATCH 1/2] abort multipart --- crates/s3s-fs/src/s3.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crates/s3s-fs/src/s3.rs b/crates/s3s-fs/src/s3.rs index a833a2d9..160f8e12 100644 --- a/crates/s3s-fs/src/s3.rs +++ b/crates/s3s-fs/src/s3.rs @@ -638,4 +638,38 @@ impl S3 for FileSystem { }; Ok(S3Response::new(output)) } + + #[tracing::instrument] + async fn abort_multipart_upload( + &self, + req: S3Request, + ) -> S3Result> { + let AbortMultipartUploadInput { + bucket, key, upload_id, .. + } = req.input; + + let upload_id = Uuid::parse_str(&upload_id).map_err(|_| s3_error!(InvalidRequest))?; + if self.verify_upload_id(req.credentials.as_ref(), &upload_id).await?.not() { + return Err(s3_error!(AccessDenied)); + } + + let prefix = format!(".upload_id-{upload_id}"); + let mut iter = try_!(fs::read_dir(&self.root).await); + while let Some(entry) = try_!(iter.next_entry().await) { + let file_name = entry.file_name(); + let name = file_name + .to_str() + .ok_or_else(|| s3_error!(InternalError, "Failed to read filename"))?; + + if name.starts_with(&prefix) { + try_!(fs::remove_file(entry.path()).await); + } + } + + self.delete_upload_id(&upload_id).await?; + + debug!(bucket = %bucket, key = %key, upload_id = %upload_id, "multipart upload aborted"); + + Ok(S3Response::new(AbortMultipartUploadOutput { ..Default::default() })) + } } From 5b84de9f8b7bc9434f0054e91b3654a6ee876317 Mon Sep 17 00:00:00 2001 From: Lynn Liu Date: Fri, 22 Sep 2023 11:27:21 -0700 Subject: [PATCH 2/2] update abort-multipart --- crates/s3s-fs/src/s3.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/s3s-fs/src/s3.rs b/crates/s3s-fs/src/s3.rs index 160f8e12..51ac1f91 100644 --- a/crates/s3s-fs/src/s3.rs +++ b/crates/s3s-fs/src/s3.rs @@ -656,10 +656,13 @@ impl S3 for FileSystem { let prefix = format!(".upload_id-{upload_id}"); let mut iter = try_!(fs::read_dir(&self.root).await); while let Some(entry) = try_!(iter.next_entry().await) { + let file_type = try_!(entry.file_type().await); + if file_type.is_file().not() { + continue; + } + let file_name = entry.file_name(); - let name = file_name - .to_str() - .ok_or_else(|| s3_error!(InternalError, "Failed to read filename"))?; + let Some(name) = file_name.to_str() else { continue }; if name.starts_with(&prefix) { try_!(fs::remove_file(entry.path()).await);