From e478dd5452d70a5ea2082337b05ad91f331f0eb6 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Mon, 26 Dec 2022 15:39:27 +0900 Subject: [PATCH] JCLOUDS-1371: JCLOUDS-1488: optimize fs prefix This reduces the number of stat calls required when prefix is deep in the filesystem hierarchy. Further optimizations to delimiter are possible. References gaul/s3proxy#473. --- .../strategy/internal/FilesystemStorageStrategyImpl.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java index f34b3aaf7c7..92216f1b103 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java @@ -353,6 +353,14 @@ public Iterable getBlobKeysInsideContainer(String container, String pref File containerFile = openFolder(container); final int containerPathLength = containerFile.getAbsolutePath().length() + 1; + if (prefix != null) { + // prefix may end with a partial directory so only list the complete parent + int index = prefix.lastIndexOf('/'); + if (index != -1) { + containerFile = new File(containerFile, prefix.substring(0, index + 1)); + } + } + populateBlobKeysInContainer(containerFile, blobNames, prefix, new Function() { @Override public String apply(String string) {