From af4ed6767e8a72ecb0547ea819379cc759eb2aae Mon Sep 17 00:00:00 2001 From: Tara Drwenski Date: Thu, 3 Oct 2024 17:02:50 -0600 Subject: [PATCH] Make MFileS3 relativize work for comparing a bucket with no key to a uri with a key --- cdm/s3/src/main/java/thredds/inventory/s3/MFileS3.java | 7 +++---- cdm/s3/src/test/java/thredds/inventory/s3/TestMFileS3.java | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cdm/s3/src/main/java/thredds/inventory/s3/MFileS3.java b/cdm/s3/src/main/java/thredds/inventory/s3/MFileS3.java index d6f5e6ba07..8d9ab9bd08 100644 --- a/cdm/s3/src/main/java/thredds/inventory/s3/MFileS3.java +++ b/cdm/s3/src/main/java/thredds/inventory/s3/MFileS3.java @@ -399,10 +399,9 @@ public String relativize(MFile other) { if (getDelimiter() != null && getDelimiter().equals("/") && getDelimiter().equals(otherS3.getDelimiter()) && cdmS3Uri.getBucket().equals(otherS3.cdmS3Uri.getBucket())) { - final String key = getKey(); - final String otherKey = otherS3.getKey(); - return key == null || otherKey == null ? "" - : Paths.get("/" + key).relativize(Paths.get("/" + otherKey)).toString(); + final String key = getKey() == null ? "/" : "/" + getKey(); + final String otherKey = otherS3.getKey() == null ? "/" : "/" + otherS3.getKey(); + return Paths.get(key).relativize(Paths.get(otherKey)).toString(); } return ""; diff --git a/cdm/s3/src/test/java/thredds/inventory/s3/TestMFileS3.java b/cdm/s3/src/test/java/thredds/inventory/s3/TestMFileS3.java index 6334bdde53..6c7a2b1c07 100644 --- a/cdm/s3/src/test/java/thredds/inventory/s3/TestMFileS3.java +++ b/cdm/s3/src/test/java/thredds/inventory/s3/TestMFileS3.java @@ -525,6 +525,9 @@ public static List getTestParameters() { {"cdms3:bucket?a/long/#delimiter=/", "cdms3:bucket?a/long/key", ""}, {"cdms3:bucket", "cdms3:bucket?a/long/key", ""}, {"cdms3:bucket?a/long/key", "cdms3:bucket", ""}, + {"cdms3:bucket#delimiter=/", "cdms3:bucket?/#delimiter=/", ""}, + {"cdms3:bucket#delimiter=/", "cdms3:bucket?key/#delimiter=/", "key"}, + {"cdms3:bucket?key#delimiter=/", "cdms3:bucket?#delimiter=/", ".."}, {"cdms3:bucket?a/long/#delimiter=/", "cdms3:bucket?a/long/key/#delimiter=/", "key"}, {"cdms3:bucket?a/long/#delimiter=/", "cdms3:bucket?a/long/key#delimiter=/", "key"}, {"cdms3:bucket?a/long#delimiter=/", "cdms3:bucket?a/long/key/#delimiter=/", "key"},