Skip to content

Commit

Permalink
fix(core): implement allByPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mulier-p committed Dec 13, 2023
1 parent 333aa0e commit 9a08860
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/java/io/kestra/storage/gcs/GcsStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@ public InputStream get(String tenantId, URI uri) throws IOException {
}

@Override
public List<URI> filesByPrefix(String tenantId, URI prefix) {
public List<URI> allByPrefix(String tenantId, URI prefix, boolean includeDirectories) {
String path = getPath(tenantId, prefix);
return blobsForPrefix(path, true)
return blobsForPrefix(path, true, includeDirectories)
.map(BlobInfo::getName)
// keep only files
.filter(blobPath -> !blobPath.endsWith("/"))
.map(blobPath -> URI.create("kestra://" + prefix.getPath() + blobPath.substring(path.length())))
.toList();
}
Expand All @@ -104,7 +102,7 @@ public List<FileAttributes> list(String tenantId, URI uri) throws IOException {
String path = getPath(tenantId, uri);
String prefix = (path.endsWith("/")) ? path : path + "/";

List<FileAttributes> list = blobsForPrefix(prefix, false)
List<FileAttributes> list = blobsForPrefix(prefix, false, true)
.map(throwFunction(this::getGcsFileAttributes))
.toList();
if(list.isEmpty()) {
Expand All @@ -114,7 +112,7 @@ public List<FileAttributes> list(String tenantId, URI uri) throws IOException {
return list;
}

private Stream<Blob> blobsForPrefix(String prefix, boolean recursive) {
private Stream<Blob> blobsForPrefix(String prefix, boolean recursive, boolean includeDirectories) {
Storage.BlobListOption[] blobListOptions = Stream.concat(
Stream.of(Storage.BlobListOption.prefix(prefix)),
recursive ? Stream.empty() : Stream.of(Storage.BlobListOption.currentDirectory())
Expand All @@ -126,7 +124,9 @@ private Stream<Blob> blobsForPrefix(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("/"));
});
}

Expand Down

0 comments on commit 9a08860

Please sign in to comment.