Skip to content

Commit

Permalink
Make MFileS3 relativize work for comparing a bucket with no key to a …
Browse files Browse the repository at this point in the history
…uri with a key
  • Loading branch information
tdrwenski committed Oct 3, 2024
1 parent 80bf151 commit af4ed67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 3 additions & 4 deletions cdm/s3/src/main/java/thredds/inventory/s3/MFileS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down
3 changes: 3 additions & 0 deletions cdm/s3/src/test/java/thredds/inventory/s3/TestMFileS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ public static List<Object[]> 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"},
Expand Down

0 comments on commit af4ed67

Please sign in to comment.