diff --git a/src/main/java/ninja/S3Dispatcher.java b/src/main/java/ninja/S3Dispatcher.java index 7de6511..44bbbb0 100644 --- a/src/main/java/ninja/S3Dispatcher.java +++ b/src/main/java/ninja/S3Dispatcher.java @@ -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 = "/"; @@ -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;