Skip to content

Commit

Permalink
Throws error if attempting to delete a non-empty bucket 🎳
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobvogel committed Sep 18, 2023
1 parent a723651 commit 6db3ad9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/ninja/S3Dispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class S3Dispatcher implements WebDispatcher {
private static final String RESPONSE_BUCKET = "Bucket";
private static final String ERROR_MULTIPART_UPLOAD_DOES_NOT_EXIST = "Multipart Upload does not exist";
private static final String ERROR_BUCKET_DOES_NOT_EXIST = "Bucket does not exist";
private static final String ERROR_BUCKET_IS_NOT_EMPTY = "Bucket is not empty";
private static final String ERROR_FILE_SYSTEM = "Problems with file system access";
private static final String PATH_DELIMITER = "/";

Expand Down Expand Up @@ -467,6 +468,15 @@ private void bucket(WebContext webContext, String bucketName) {
if (!bucket.exists()) {
signalObjectError(webContext, bucketName, null, S3ErrorCode.NoSuchBucket, ERROR_BUCKET_DOES_NOT_EXIST);
} else {
if (bucket.countObjects("") > 0) {
signalObjectError(webContext,
bucketName,
null,
S3ErrorCode.BucketNotEmpty,
ERROR_BUCKET_IS_NOT_EMPTY);
return;
}

if (!bucket.delete()) {
signalObjectError(webContext, bucketName, null, S3ErrorCode.InternalError, ERROR_FILE_SYSTEM);
return;
Expand Down

0 comments on commit 6db3ad9

Please sign in to comment.