Skip to content

Commit

Permalink
Throws error if attempting to create an existing bucket 馃
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobvogel committed Sep 18, 2023
1 parent 6db3ad9 commit 85b37b6
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 @@ -93,6 +93,7 @@ public class S3Dispatcher implements WebDispatcher {
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_BUCKET_ALREADY_OWNED_BY_YOU = "Bucket already owned by you";
private static final String ERROR_FILE_SYSTEM = "Problems with file system access";
private static final String PATH_DELIMITER = "/";

Expand Down Expand Up @@ -486,6 +487,15 @@ private void bucket(WebContext webContext, String bucketName) {
webContext.respondWith().status(HttpResponseStatus.OK);
}
} else if (HttpMethod.PUT.equals(method)) {
if (bucket.exists()) {
signalObjectError(webContext,
bucketName,
null,
S3ErrorCode.BucketAlreadyOwnedByYou,
ERROR_BUCKET_ALREADY_OWNED_BY_YOU);
return;
}

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

0 comments on commit 85b37b6

Please sign in to comment.