From 6f5400a62c8002a01ed6cc4fd55708321b36e9cd Mon Sep 17 00:00:00 2001 From: John Bogovic Date: Tue, 3 Dec 2024 11:40:28 -0500 Subject: [PATCH] wip: notes and TODOs in KeyValueAccess --- .../GoogleCloudStorageKeyValueAccess.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/janelia/saalfeldlab/n5/googlecloud/GoogleCloudStorageKeyValueAccess.java b/src/main/java/org/janelia/saalfeldlab/n5/googlecloud/GoogleCloudStorageKeyValueAccess.java index 95105be..c506654 100644 --- a/src/main/java/org/janelia/saalfeldlab/n5/googlecloud/GoogleCloudStorageKeyValueAccess.java +++ b/src/main/java/org/janelia/saalfeldlab/n5/googlecloud/GoogleCloudStorageKeyValueAccess.java @@ -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. * @@ -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)); @@ -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()); @@ -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(); } @@ -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 @@ -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"); } @@ -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));