feat(S3): provide bucketExists() method
This commit is contained in:
parent
f4a6715bd2
commit
2f1f9faeae
@ -0,0 +1,19 @@
|
|||||||
|
package org.cryptomator.data.cloud.s3;
|
||||||
|
|
||||||
|
public class S3CloudApiExceptions {
|
||||||
|
|
||||||
|
public enum S3CloudApiErrorCodes {
|
||||||
|
NO_SUCH_BUCKET("NoSuchBucket");
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
S3CloudApiErrorCodes(final String newValue) {
|
||||||
|
value = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
|
|
||||||
import com.amazonaws.event.ProgressListener;
|
import com.amazonaws.event.ProgressListener;
|
||||||
import com.amazonaws.services.s3.AmazonS3;
|
import com.amazonaws.services.s3.AmazonS3;
|
||||||
|
import com.amazonaws.services.s3.model.AmazonS3Exception;
|
||||||
import com.amazonaws.services.s3.model.CopyObjectResult;
|
import com.amazonaws.services.s3.model.CopyObjectResult;
|
||||||
import com.amazonaws.services.s3.model.DeleteObjectsRequest;
|
import com.amazonaws.services.s3.model.DeleteObjectsRequest;
|
||||||
import com.amazonaws.services.s3.model.DeleteObjectsRequest.KeyVersion;
|
import com.amazonaws.services.s3.model.DeleteObjectsRequest.KeyVersion;
|
||||||
@ -22,6 +23,8 @@ import org.cryptomator.data.util.CopyStream;
|
|||||||
import org.cryptomator.domain.S3Cloud;
|
import org.cryptomator.domain.S3Cloud;
|
||||||
import org.cryptomator.domain.exception.BackendException;
|
import org.cryptomator.domain.exception.BackendException;
|
||||||
import org.cryptomator.domain.exception.CloudNodeAlreadyExistsException;
|
import org.cryptomator.domain.exception.CloudNodeAlreadyExistsException;
|
||||||
|
import org.cryptomator.domain.exception.FatalBackendException;
|
||||||
|
import org.cryptomator.domain.exception.NoSuchBucketException;
|
||||||
import org.cryptomator.domain.exception.NoSuchCloudFileException;
|
import org.cryptomator.domain.exception.NoSuchCloudFileException;
|
||||||
import org.cryptomator.domain.exception.authentication.NoAuthenticationProvidedException;
|
import org.cryptomator.domain.exception.authentication.NoAuthenticationProvidedException;
|
||||||
import org.cryptomator.domain.usecases.ProgressAware;
|
import org.cryptomator.domain.usecases.ProgressAware;
|
||||||
@ -106,6 +109,20 @@ class S3Impl {
|
|||||||
return S3CloudNodeFactory.folder(parent, name, parent.getKey() + name);
|
return S3CloudNodeFactory.folder(parent, name, parent.getKey() + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean bucketExists() throws BackendException {
|
||||||
|
try {
|
||||||
|
client().listObjectsV2(cloud.s3Bucket());
|
||||||
|
} catch(AmazonS3Exception ex) {
|
||||||
|
if (ex.getErrorCode().equals(S3CloudApiExceptions.S3CloudApiErrorCodes.NO_SUCH_BUCKET.getValue())) {
|
||||||
|
throw new NoSuchBucketException(cloud.s3Bucket());
|
||||||
|
} else {
|
||||||
|
throw new FatalBackendException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean exists(S3Node node) {
|
public boolean exists(S3Node node) {
|
||||||
String key = node.getKey();
|
String key = node.getKey();
|
||||||
|
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package org.cryptomator.domain.exception;
|
||||||
|
|
||||||
|
public class NoSuchBucketException extends BackendException {
|
||||||
|
|
||||||
|
public NoSuchBucketException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public NoSuchBucketException(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user