diff --git a/weed/s3api/s3api_object_handlers_list.go b/weed/s3api/s3api_object_handlers_list.go index a96a6fe10..0e9e58c40 100644 --- a/weed/s3api/s3api_object_handlers_list.go +++ b/weed/s3api/s3api_object_handlers_list.go @@ -150,11 +150,10 @@ func (s3a *S3ApiServer) listFilerEntries(bucket string, originalPrefix string, m // check filer err = s3a.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error { - var lastEntryWasCommonPrefix bool - var lastCommonPrefixName string - for { empty := true + var lastEntryWasCommonPrefix bool + var lastCommonPrefixName string nextMarker, doErr = s3a.doListFilerEntries(client, reqDir, prefix, cursor, marker, delimiter, false, func(dir string, entry *filer_pb.Entry) { empty = false @@ -339,7 +338,6 @@ func (s3a *S3ApiServer) doListFilerEntries(client filer_pb.SeaweedFilerClient, d return } if cursor.maxKeys <= 0 { - cursor.isTruncated = true return } @@ -393,8 +391,18 @@ func (s3a *S3ApiServer) doListFilerEntries(client filer_pb.SeaweedFilerClient, d } } if cursor.maxKeys <= 0 { - cursor.isTruncated = true - continue + // Check if there are more entries available by trying to peek at the next one + _, nextRecvErr := stream.Recv() + if nextRecvErr == nil { + // There is another entry available, so we're truncated + cursor.isTruncated = true + } else if nextRecvErr != io.EOF { + // Some other error occurred + err = fmt.Errorf("peeking next entry: %v", nextRecvErr) + return + } + // If nextRecvErr == io.EOF, there are no more entries, so isTruncated remains false + break } entry := resp.Entry nextMarker = entry.Name @@ -464,6 +472,7 @@ func (s3a *S3ApiServer) doListFilerEntries(client filer_pb.SeaweedFilerClient, d // Create logical entries for objects that have .versions directories for _, versionsDir := range versionsDirs { if cursor.maxKeys <= 0 { + // We have versioned objects remaining but can't process them due to limit cursor.isTruncated = true break }