mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-19 01:17:56 +08:00
avoid int bigger than math.MaxInt32
fix https://github.com/chrislusf/seaweedfs/issues/2363
This commit is contained in:
@@ -23,15 +23,15 @@ func splitPattern(pattern string) (prefix string, restPattern string) {
|
|||||||
// For now, prefix and namePattern are mutually exclusive
|
// For now, prefix and namePattern are mutually exclusive
|
||||||
func (f *Filer) ListDirectoryEntries(ctx context.Context, p util.FullPath, startFileName string, inclusive bool, limit int64, prefix string, namePattern string, namePatternExclude string) (entries []*Entry, hasMore bool, err error) {
|
func (f *Filer) ListDirectoryEntries(ctx context.Context, p util.FullPath, startFileName string, inclusive bool, limit int64, prefix string, namePattern string, namePatternExclude string) (entries []*Entry, hasMore bool, err error) {
|
||||||
|
|
||||||
|
if limit > math.MaxInt32-1 {
|
||||||
|
limit = math.MaxInt32 - 1
|
||||||
|
}
|
||||||
|
|
||||||
_, err = f.StreamListDirectoryEntries(ctx, p, startFileName, inclusive, limit+1, prefix, namePattern, namePatternExclude, func(entry *Entry) bool {
|
_, err = f.StreamListDirectoryEntries(ctx, p, startFileName, inclusive, limit+1, prefix, namePattern, namePatternExclude, func(entry *Entry) bool {
|
||||||
entries = append(entries, entry)
|
entries = append(entries, entry)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
if limit == math.MaxInt64 {
|
|
||||||
limit = math.MaxInt64 - 1
|
|
||||||
}
|
|
||||||
|
|
||||||
hasMore = int64(len(entries)) >= limit+1
|
hasMore = int64(len(entries)) >= limit+1
|
||||||
if hasMore {
|
if hasMore {
|
||||||
entries = entries[:limit]
|
entries = entries[:limit]
|
||||||
|
@@ -3,6 +3,7 @@ package filer
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/chrislusf/seaweedfs/weed/util"
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -120,6 +121,10 @@ func (t *FilerStorePathTranlator) ListDirectoryPrefixedEntries(ctx context.Conte
|
|||||||
|
|
||||||
newFullPath := t.translatePath(dirPath)
|
newFullPath := t.translatePath(dirPath)
|
||||||
|
|
||||||
|
if limit > math.MaxInt32-1 {
|
||||||
|
limit = math.MaxInt32 - 1
|
||||||
|
}
|
||||||
|
|
||||||
return t.actualStore.ListDirectoryPrefixedEntries(ctx, newFullPath, startFileName, includeStartFile, limit, prefix, func(entry *Entry) bool {
|
return t.actualStore.ListDirectoryPrefixedEntries(ctx, newFullPath, startFileName, includeStartFile, limit, prefix, func(entry *Entry) bool {
|
||||||
entry.FullPath = dirPath[:len(t.storeRoot)-1] + entry.FullPath
|
entry.FullPath = dirPath[:len(t.storeRoot)-1] + entry.FullPath
|
||||||
return eachEntryFunc(entry)
|
return eachEntryFunc(entry)
|
||||||
|
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/viant/ptrie"
|
"github.com/viant/ptrie"
|
||||||
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -248,6 +249,9 @@ func (fsw *FilerStoreWrapper) ListDirectoryPrefixedEntries(ctx context.Context,
|
|||||||
defer func() {
|
defer func() {
|
||||||
stats.FilerStoreHistogram.WithLabelValues(actualStore.GetName(), "prefixList").Observe(time.Since(start).Seconds())
|
stats.FilerStoreHistogram.WithLabelValues(actualStore.GetName(), "prefixList").Observe(time.Since(start).Seconds())
|
||||||
}()
|
}()
|
||||||
|
if limit > math.MaxInt32-1 {
|
||||||
|
limit = math.MaxInt32 - 1
|
||||||
|
}
|
||||||
glog.V(4).Infof("ListDirectoryPrefixedEntries %s from %s prefix %s limit %d", dirPath, startFileName, prefix, limit)
|
glog.V(4).Infof("ListDirectoryPrefixedEntries %s from %s prefix %s limit %d", dirPath, startFileName, prefix, limit)
|
||||||
lastFileName, err = actualStore.ListDirectoryPrefixedEntries(ctx, dirPath, startFileName, includeStartFile, limit, prefix, eachEntryFunc)
|
lastFileName, err = actualStore.ListDirectoryPrefixedEntries(ctx, dirPath, startFileName, includeStartFile, limit, prefix, eachEntryFunc)
|
||||||
if err == ErrUnsupportedListDirectoryPrefixed {
|
if err == ErrUnsupportedListDirectoryPrefixed {
|
||||||
|
@@ -101,9 +101,13 @@ 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.
|
// Redundancy limit to make it correctly judge whether it is the last file.
|
||||||
redLimit := limit
|
redLimit := limit
|
||||||
if limit != math.MaxInt32 && limit != 0 {
|
|
||||||
|
if limit < math.MaxInt32 && limit != 0 {
|
||||||
redLimit = limit + 1
|
redLimit = limit + 1
|
||||||
}
|
}
|
||||||
|
if redLimit > math.MaxInt32 {
|
||||||
|
redLimit = math.MaxInt32
|
||||||
|
}
|
||||||
request := &ListEntriesRequest{
|
request := &ListEntriesRequest{
|
||||||
Directory: string(fullDirPath),
|
Directory: string(fullDirPath),
|
||||||
Prefix: prefix,
|
Prefix: prefix,
|
||||||
|
Reference in New Issue
Block a user