Skip to content

Commit

Permalink
Merge pull request #1390 from tdrwenski/fix-s3-relativize
Browse files Browse the repository at this point in the history
Fix MFileS3::relativize
  • Loading branch information
tdrwenski authored Oct 4, 2024
2 parents 80bf151 + af4ed67 commit 5fa45ef
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 5fa45ef

Please sign in to comment.