Skip to content

Commit 9fca52f

Browse files
committed
S3 and IBM improved ExistsDirectory
1 parent 0df26a4 commit 9fca52f

File tree

2 files changed

+14
-40
lines changed

2 files changed

+14
-40
lines changed

gxexternalproviders/src/main/java/com/genexus/db/driver/ExternalProviderIBM.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -275,25 +275,12 @@ public String getDirectory(String directoryName) {
275275
}
276276

277277
public boolean existsDirectory(String directoryName) {
278-
directoryName = StorageUtils.normalizeDirectoryName(directoryName);
279-
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
280-
.withBucketName(bucket).withDelimiter(StorageUtils.DELIMITER);
281-
List<String> directories = new ArrayList<String>();
282-
for (String prefix : client.listObjects(listObjectsRequest).getCommonPrefixes()) {
283-
directories.add(prefix);
284-
getAllDirectories(prefix, directories);
285-
}
286-
return directories.contains(directoryName);
287-
}
288-
289-
public void getAllDirectories(String directoryName, List<String> directories) {
290-
directoryName = StorageUtils.normalizeDirectoryName(directoryName);
291-
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
292-
.withBucketName(bucket).withPrefix(directoryName).withDelimiter(StorageUtils.DELIMITER);
293-
for (String prefix : client.listObjects(listObjectsRequest).getCommonPrefixes()) {
294-
directories.add(prefix);
295-
getAllDirectories(prefix, directories);
296-
}
278+
ListObjectsV2Request listObjectsRequest = new ListObjectsV2Request()
279+
.withBucketName(bucket)
280+
.withDelimiter(StorageUtils.DELIMITER)
281+
.withPrefix(StorageUtils.normalizeDirectoryName(directoryName))
282+
.withMaxKeys(1);
283+
return client.listObjectsV2(listObjectsRequest).getKeyCount() > 0;
297284
}
298285

299286
public void createDirectory(String directoryName) {

gxexternalproviders/src/main/java/com/genexus/db/driver/ExternalProviderS3.java

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -328,27 +328,14 @@ public String getDirectory(String directoryName) {
328328
}
329329
}
330330

331-
public boolean existsDirectory(String directoryName) {
332-
directoryName = StorageUtils.normalizeDirectoryName(directoryName);
333-
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
334-
.withBucketName(bucket).withDelimiter(StorageUtils.DELIMITER);
335-
List<String> directories = new ArrayList<String>();
336-
for (String prefix : client.listObjects(listObjectsRequest).getCommonPrefixes()) {
337-
directories.add(prefix);
338-
getAllDirectories(prefix, directories);
339-
}
340-
return directories.contains(directoryName);
341-
}
342-
343-
public void getAllDirectories(String directoryName, List<String> directories) {
344-
directoryName = StorageUtils.normalizeDirectoryName(directoryName);
345-
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
346-
.withBucketName(bucket).withPrefix(directoryName).withDelimiter(StorageUtils.DELIMITER);
347-
for (String prefix : client.listObjects(listObjectsRequest).getCommonPrefixes()) {
348-
directories.add(prefix);
349-
getAllDirectories(prefix, directories);
350-
}
351-
}
331+
public boolean existsDirectory(String directoryName) {
332+
ListObjectsV2Request listObjectsRequest = new ListObjectsV2Request()
333+
.withBucketName(bucket)
334+
.withDelimiter(StorageUtils.DELIMITER)
335+
.withPrefix(StorageUtils.normalizeDirectoryName(directoryName))
336+
.withMaxKeys(1);
337+
return client.listObjectsV2(listObjectsRequest).getKeyCount() > 0;
338+
}
352339

353340
public void createDirectory(String directoryName) {
354341
ensureFolder(directoryName);

0 commit comments

Comments
 (0)