Skip to content

Commit 5456b02

Browse files
committed
1 parent facf8f4 commit 5456b02

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

h2o-persist-s3/src/main/java/water/persist/PersistS3.java

+18
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,24 @@ public PersistEntry[] list(String path) {
237237
return entries;
238238
}
239239

240+
@Override
241+
public String getParent(String path) {
242+
String[] bk = decodePath(path);
243+
String bucket = bk[0];
244+
String key = bk[1];
245+
if (key.endsWith("/")) {
246+
key = key.substring(0, key.length() - 1);
247+
}
248+
if (key == null || key.isEmpty()) {
249+
throw new IllegalArgumentException("No parent exists for a bucket-only path: " + path);
250+
}
251+
int lastSlash = key.lastIndexOf("/");
252+
if (lastSlash == -1) {
253+
return "s3://" + bucket;
254+
}
255+
return "s3://" + bucket + "/" + key.substring(0, lastSlash);
256+
}
257+
240258
@Override
241259
public InputStream open(String path) {
242260
String[] bk = decodePath(path);

0 commit comments

Comments
 (0)