Skip to content

Commit

Permalink
Handles FS access errors in S3-style interface 馃彴
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobvogel committed Sep 18, 2023
1 parent 0c1b575 commit db11b75
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 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_FILE_SYSTEM = "Problems with file system access";
private static final String PATH_DELIMITER = "/";

private static class S3Request {
Expand Down Expand Up @@ -466,17 +467,25 @@ private void bucket(WebContext webContext, String bucketName) {
if (!bucket.exists()) {
signalObjectError(webContext, bucketName, null, S3ErrorCode.NoSuchBucket, ERROR_BUCKET_DOES_NOT_EXIST);
} else {
bucket.delete();
if (!bucket.delete()) {
signalObjectError(webContext, bucketName, null, S3ErrorCode.InternalError, ERROR_FILE_SYSTEM);
return;
}

signalObjectSuccess(webContext);
webContext.respondWith().status(HttpResponseStatus.OK);
}
} else if (HttpMethod.PUT.equals(method)) {
bucket.create();
if (!bucket.create()) {
signalObjectError(webContext, bucketName, null, S3ErrorCode.InternalError, ERROR_FILE_SYSTEM);
return;
}

// in order to allow creation of public buckets, we support a single canned access control list
String cannedAccessControlList = webContext.getHeader("x-amz-acl");
if (Strings.areEqual(cannedAccessControlList, "public-read-write")) {
bucket.makePublic();
if (Strings.areEqual(cannedAccessControlList, "public-read-write") && !bucket.makePublic()) {
signalObjectError(webContext, bucketName, null, S3ErrorCode.InternalError, ERROR_FILE_SYSTEM);
return;
}

signalObjectSuccess(webContext);
Expand Down Expand Up @@ -573,7 +582,10 @@ private boolean checkObjectRequest(WebContext webContext, Bucket bucket, String

if (!bucket.exists()) {
if (storage.isAutocreateBuckets()) {
bucket.create();
if (!bucket.create()) {
signalObjectError(webContext, bucket.getName(), id, S3ErrorCode.InternalError, ERROR_FILE_SYSTEM);
return false;
}
} else {
signalObjectError(webContext,
bucket.getName(),
Expand Down

0 comments on commit db11b75

Please sign in to comment.