Skip to content

Commit f76b496

Browse files
vadmesteharshavardhana
authored andcommitted
fix: Correct v2 listing of more than 1000 objects (#580)
Fix listing objects (infinite loop) when there is more than 1000 objects in the server.
1 parent 73ca5e5 commit f76b496

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

api/src/main/java/io/minio/MinioClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,7 @@ private synchronized void populate() {
24262426
}
24272427

24282428
String continuationToken = null;
2429-
if (this.listBucketResult != null && delimiter != null) {
2429+
if (this.listBucketResult != null) {
24302430
continuationToken = listBucketResult.nextContinuationToken();
24312431
}
24322432

functional/FunctionalTest.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,43 @@ public static void listObject_test4() throws Exception {
668668
}
669669

670670
/**
671-
* Test: listObjects(bucketName, final String prefix, final boolean recursive, final boolean useVersion1).
671+
* Test: recursive: listObjects(bucketName, final String prefix, final boolean recursive).
672672
*/
673673
public static void listObject_test5() throws Exception {
674+
int i;
675+
int objCount = 1050;
676+
677+
System.out.println("Test: recursive: listObjects(final String bucketName, final String prefix"
678+
+ ", final boolean recursive)");
679+
String[] objectNames = new String[objCount];
680+
681+
String baseFilename = createFile(1);
682+
for (i = 0; i < objCount; i++) {
683+
objectNames[i] = baseFilename + "-" + i;
684+
client.putObject(bucketName, objectNames[i], baseFilename);
685+
}
686+
Files.delete(Paths.get(baseFilename));
687+
688+
i = 0;
689+
for (Result<?> r : client.listObjects(bucketName, "minio", true)) {
690+
ignore(i++, r.get());
691+
}
692+
693+
// Check the number of uploaded objects
694+
if (i != objCount) {
695+
throw new Exception("[FAILED] Test: recursive: listObject_test5(), number of items, expected: "
696+
+ objCount + ", found: " + i);
697+
}
698+
699+
for (i = 0; i < objCount; i++) {
700+
client.removeObject(bucketName, objectNames[i]);
701+
}
702+
}
703+
704+
/**
705+
* Test: listObjects(bucketName, final String prefix, final boolean recursive, final boolean useVersion1).
706+
*/
707+
public static void listObject_test6() throws Exception {
674708
int i;
675709
System.out.println("Test: listObjects(final String bucketName, final String prefix, final boolean recursive,"
676710
+ " final boolean useVersion1)");
@@ -1544,6 +1578,7 @@ public static void runTests() throws Exception {
15441578
listObject_test3();
15451579
listObject_test4();
15461580
listObject_test5();
1581+
listObject_test6();
15471582

15481583
removeObject_test1();
15491584
removeObject_test2();

0 commit comments

Comments
 (0)