Merge pull request #1892 from wuh-fnst/listMultipartIsLast

make “List” correctly judge whether it is the last file
This commit is contained in:
Chris Lu
2021-03-11 20:58:58 -08:00
committed by GitHub

View File

@@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"math"
"os" "os"
"strings" "strings"
"time" "time"
@@ -101,12 +102,16 @@ func SeaweedList(client SeaweedFilerClient, parentDirectoryPath, prefix string,
} }
func doSeaweedList(client SeaweedFilerClient, fullDirPath util.FullPath, prefix string, fn EachEntryFunciton, startFrom string, inclusive bool, limit uint32) (err error) { func doSeaweedList(client SeaweedFilerClient, fullDirPath util.FullPath, prefix string, fn EachEntryFunciton, startFrom string, inclusive bool, limit uint32) (err error) {
// Redundancy limit to make it correctly judge whether it is the last file.
redLimit := limit
if limit != math.MaxInt32 && limit != 0{
redLimit = limit + 1
}
request := &ListEntriesRequest{ request := &ListEntriesRequest{
Directory: string(fullDirPath), Directory: string(fullDirPath),
Prefix: prefix, Prefix: prefix,
StartFromFileName: startFrom, StartFromFileName: startFrom,
Limit: limit, Limit: redLimit,
InclusiveStartFrom: inclusive, InclusiveStartFrom: inclusive,
} }
@@ -119,6 +124,7 @@ func doSeaweedList(client SeaweedFilerClient, fullDirPath util.FullPath, prefix
} }
var prevEntry *Entry var prevEntry *Entry
count := 0
for { for {
resp, recvErr := stream.Recv() resp, recvErr := stream.Recv()
if recvErr != nil { if recvErr != nil {
@@ -139,6 +145,10 @@ func doSeaweedList(client SeaweedFilerClient, fullDirPath util.FullPath, prefix
} }
} }
prevEntry = resp.Entry prevEntry = resp.Entry
count++
if count > int(limit) && limit != 0 {
prevEntry = nil
}
} }
return nil return nil