diff --git a/src/main/java/io/kestra/storage/s3/S3Storage.java b/src/main/java/io/kestra/storage/s3/S3Storage.java index 2bcfe7d..1a379df 100644 --- a/src/main/java/io/kestra/storage/s3/S3Storage.java +++ b/src/main/java/io/kestra/storage/s3/S3Storage.java @@ -66,11 +66,9 @@ public InputStream get(String tenantId, URI uri) throws IOException { } @Override - public List filesByPrefix(String tenantId, URI prefix) { + public List allByPrefix(String tenantId, URI prefix, boolean includeDirectories) { String path = getPath(tenantId, prefix); - return keysForPrefix(path, true) - // keep only files - .filter(key -> !key.endsWith("/")) + return keysForPrefix(path, true, includeDirectories) .map(key -> URI.create("kestra://" + prefix.getPath() + key.substring(path.length()))) .toList(); } @@ -102,7 +100,7 @@ public List list(String tenantId, URI uri) throws IOException { String path = getPath(tenantId, uri); String prefix = path.endsWith("/") ? path : path + "/"; try { - List list = keysForPrefix(prefix, false) + List list = keysForPrefix(prefix, false, true) .map(throwFunction(this::getFileAttributes)) .toList(); if (list.isEmpty()) { @@ -117,7 +115,7 @@ public List list(String tenantId, URI uri) throws IOException { } } - private Stream keysForPrefix(String prefix, boolean recursive) { + private Stream keysForPrefix(String prefix, boolean recursive, boolean includeDirectories) { ListObjectsV2Request request = ListObjectsV2Request.builder() .bucket(s3Config.getBucket()) .prefix(prefix) @@ -130,7 +128,9 @@ private Stream keysForPrefix(String prefix, boolean recursive) { // Remove recursive result and requested dir return !key.isEmpty() && !Objects.equals(key, prefix) - && (recursive || Path.of(key).getParent() == null); + && !key.equals("/") + && (recursive || Path.of(key).getParent() == null) + && (includeDirectories || !key.endsWith("/")); }); }