Skip to content

Commit

Permalink
wip: notes and TODOs in KeyValueAccess
Browse files Browse the repository at this point in the history
  • Loading branch information
bogovicj committed Dec 3, 2024
1 parent b208d64 commit 6f5400a
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public GoogleCloudStorageKeyValueAccess(final Storage storage, final URI contain
this(storage, new GoogleCloudStorageURI(containerURI), createBucket);
}


/**
* Creates a {@link KeyValueAccess} using a google cloud storage backend.
*
Expand All @@ -97,6 +98,7 @@ public GoogleCloudStorageKeyValueAccess(final Storage storage, final GoogleCloud
this.containerURI = containerURI;
this.bucketName = containerURI.getBucket();

// move this logic
if (!bucketExists(bucketName)) {
if (createBucket) {
storage.create(BucketInfo.of(bucketName));
Expand All @@ -108,6 +110,7 @@ public GoogleCloudStorageKeyValueAccess(final Storage storage, final GoogleCloud
}

private boolean bucketExists(final String bucketName) {
// TODO why private?

final Bucket bucket = storage.get(bucketName);
return (bucket != null && bucket.exists());
Expand Down Expand Up @@ -251,7 +254,7 @@ private boolean keyExists(final String key) {

private static boolean blobExists(final Blob blob) {

// TODO document this
// TODO document this
return blob != null && blob.exists();
}

Expand All @@ -278,10 +281,14 @@ private static String removeLeadingSlash(final String path) {
@Override
public boolean isDirectory(final String normalPath) {

// TODO can this (or bucketExists) be implemented with blobExists?

final String key = removeLeadingSlash(addTrailingSlash(normalPath));
if (key.equals(normalize("/"))) {
return bucketExists(bucketName);
} else {
// TODO probably need to try/catch if bucket does not exist

// not every directory will have a directly stored in the backend,
// for example, if the container contents was copied to GCS with the cli
// in that case, check if any keys exist with the prefix, if so, it's a directory
Expand Down Expand Up @@ -336,6 +343,8 @@ public String[] listDirectories(final String normalPath) {

private String[] list(final String normalPath, final boolean onlyDirectories) {

// TODO what should happen when listing a non-existent bucket / path?

if (!isDirectory(normalPath)) {
throw new N5Exception.N5IOException(normalPath + " is not a valid group");
}
Expand Down Expand Up @@ -370,6 +379,10 @@ public String[] list(final String normalPath) {
@Override
public void createDirectories(final String normalPath) {

// TODO move bucket creation here?
// i.e. if this fails with a "bucket does not exist" error,
// create the bucket

String path = "";
for (final String component : components(removeLeadingSlash(normalPath))) {
path = addTrailingSlash(compose(path, component));
Expand Down

0 comments on commit 6f5400a

Please sign in to comment.