From 5c27419924badab26b484a21803880abbd49a882 Mon Sep 17 00:00:00 2001 From: Caleb Hulbert Date: Thu, 12 Dec 2024 10:37:37 -0500 Subject: [PATCH] fix: update cached bucket exists flag after delete bucket --- .../n5/s3/AmazonS3KeyValueAccess.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/janelia/saalfeldlab/n5/s3/AmazonS3KeyValueAccess.java b/src/main/java/org/janelia/saalfeldlab/n5/s3/AmazonS3KeyValueAccess.java index dcaa2ff..a802f80 100644 --- a/src/main/java/org/janelia/saalfeldlab/n5/s3/AmazonS3KeyValueAccess.java +++ b/src/main/java/org/janelia/saalfeldlab/n5/s3/AmazonS3KeyValueAccess.java @@ -141,11 +141,10 @@ public AmazonS3KeyValueAccess(final AmazonS3 s3, final URI containerURI, final b } private boolean bucketExists() { - if (bucketCheckedAndExists != null) - return bucketCheckedAndExists; - bucketCheckedAndExists = s3.doesBucketExistV2(bucketName); - return bucketCheckedAndExists; + return bucketCheckedAndExists = bucketCheckedAndExists != null + ? bucketCheckedAndExists + : s3.doesBucketExistV2(bucketName); } private void createBucket() { @@ -156,7 +155,6 @@ private void createBucket() { if (bucketExists()) return; - Region region; try { region = s3.getRegion(); @@ -172,6 +170,21 @@ private void createBucket() { } + private void deleteBucket() { + if (!createBucket) + throw new N5Exception("Delete Bucket Not Allowed"); + + if (!bucketExists()) + return; + + try { + s3.deleteBucket(bucketName); + bucketCheckedAndExists = false; + } catch (Exception e) { + throw new N5Exception("Could not delete bucket " + bucketName, e); + } + } + @Override public String[] components(final String path) { @@ -516,7 +529,7 @@ public void delete(final String normalPath) { } } - s3.deleteBucket(bucketName); + deleteBucket(); return; }