diff --git a/weed/filer2/abstract_sql/abstract_sql_store.go b/weed/filer2/abstract_sql/abstract_sql_store.go index b6da8e74e..a90c1341f 100644 --- a/weed/filer2/abstract_sql/abstract_sql_store.go +++ b/weed/filer2/abstract_sql/abstract_sql_store.go @@ -199,8 +199,10 @@ func (store *AbstractSqlStore) ListDirectoryPrefixedEntries(ctx context.Context, if prefix == "" { return notPrefixed, nil } + var lastFileName string for count < limit { for _, entry := range notPrefixed { + lastFileName = entry.Name() if strings.HasPrefix(entry.Name(), prefix) { count++ entries = append(entries, entry) @@ -210,10 +212,14 @@ func (store *AbstractSqlStore) ListDirectoryPrefixedEntries(ctx context.Context, break } - notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, startFileName, inclusive, limit) + notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, lastFileName, inclusive, limit) if err != nil { return nil, err } + + if len(notPrefixed) == 0 { + break + } } return entries, nil diff --git a/weed/filer2/cassandra/cassandra_store.go b/weed/filer2/cassandra/cassandra_store.go index 225ad02a3..dc29371d8 100644 --- a/weed/filer2/cassandra/cassandra_store.go +++ b/weed/filer2/cassandra/cassandra_store.go @@ -137,8 +137,10 @@ func (store *CassandraStore) ListDirectoryPrefixedEntries(ctx context.Context, f if prefix == "" { return notPrefixed, nil } + var lastFileName string for count < limit { for _, entry := range notPrefixed { + lastFileName = entry.Name() if strings.HasPrefix(entry.Name(), prefix) { count++ entries = append(entries, entry) @@ -148,10 +150,14 @@ func (store *CassandraStore) ListDirectoryPrefixedEntries(ctx context.Context, f break } - notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, startFileName, inclusive, limit) + notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, lastFileName, inclusive, limit) if err != nil { return nil, err } + + if len(notPrefixed) == 0 { + break + } } return entries, nil diff --git a/weed/filer2/etcd/etcd_store.go b/weed/filer2/etcd/etcd_store.go index a1bf9bf3c..9b4e21917 100644 --- a/weed/filer2/etcd/etcd_store.go +++ b/weed/filer2/etcd/etcd_store.go @@ -145,8 +145,10 @@ func (store *EtcdStore) ListDirectoryPrefixedEntries(ctx context.Context, fullpa if prefix == "" { return notPrefixed, nil } + var lastFileName string for count < limit { for _, entry := range notPrefixed { + lastFileName = entry.Name() if strings.HasPrefix(entry.Name(), prefix) { count++ entries = append(entries, entry) @@ -156,10 +158,14 @@ func (store *EtcdStore) ListDirectoryPrefixedEntries(ctx context.Context, fullpa break } - notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, startFileName, inclusive, limit) + notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, lastFileName, inclusive, limit) if err != nil { return nil, err } + + if len(notPrefixed) == 0 { + break + } } return entries, nil diff --git a/weed/filer2/leveldb/leveldb_store.go b/weed/filer2/leveldb/leveldb_store.go index 5b118884e..0d6a62212 100644 --- a/weed/filer2/leveldb/leveldb_store.go +++ b/weed/filer2/leveldb/leveldb_store.go @@ -170,8 +170,10 @@ func (store *LevelDBStore) ListDirectoryPrefixedEntries(ctx context.Context, ful if prefix == "" { return notPrefixed, nil } + var lastFileName string for count < limit { for _, entry := range notPrefixed { + lastFileName = entry.Name() if strings.HasPrefix(entry.Name(), prefix) { count++ entries = append(entries, entry) @@ -181,10 +183,14 @@ func (store *LevelDBStore) ListDirectoryPrefixedEntries(ctx context.Context, ful break } - notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, startFileName, inclusive, limit) + notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, lastFileName, inclusive, limit) if err != nil { return nil, err } + + if len(notPrefixed) == 0 { + break + } } return entries, nil diff --git a/weed/filer2/leveldb2/leveldb2_store.go b/weed/filer2/leveldb2/leveldb2_store.go index fdff3c92d..a8e915e79 100644 --- a/weed/filer2/leveldb2/leveldb2_store.go +++ b/weed/filer2/leveldb2/leveldb2_store.go @@ -179,8 +179,10 @@ func (store *LevelDB2Store) ListDirectoryPrefixedEntries(ctx context.Context, fu if prefix == "" { return notPrefixed, nil } + var lastFileName string for count < limit { for _, entry := range notPrefixed { + lastFileName = entry.Name() if strings.HasPrefix(entry.Name(), prefix) { count++ entries = append(entries, entry) @@ -190,10 +192,14 @@ func (store *LevelDB2Store) ListDirectoryPrefixedEntries(ctx context.Context, fu break } - notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, startFileName, inclusive, limit) + notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, lastFileName, inclusive, limit) if err != nil { return nil, err } + + if len(notPrefixed) == 0 { + break + } } return entries, nil diff --git a/weed/filer2/mongodb/mongodb_store.go b/weed/filer2/mongodb/mongodb_store.go index a1502430c..00f710f1f 100644 --- a/weed/filer2/mongodb/mongodb_store.go +++ b/weed/filer2/mongodb/mongodb_store.go @@ -178,8 +178,10 @@ func (store *MongodbStore) ListDirectoryPrefixedEntries(ctx context.Context, ful if prefix == "" { return notPrefixed, nil } + var lastFileName string for count < limit { for _, entry := range notPrefixed { + lastFileName = entry.Name() if strings.HasPrefix(entry.Name(), prefix) { count++ entries = append(entries, entry) @@ -189,10 +191,14 @@ func (store *MongodbStore) ListDirectoryPrefixedEntries(ctx context.Context, ful break } - notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, startFileName, inclusive, limit) + notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, lastFileName, inclusive, limit) if err != nil { return nil, err } + + if len(notPrefixed) == 0 { + break + } } return entries, nil diff --git a/weed/filer2/redis/universal_redis_store.go b/weed/filer2/redis/universal_redis_store.go index 0c90b8993..a3a8f866e 100644 --- a/weed/filer2/redis/universal_redis_store.go +++ b/weed/filer2/redis/universal_redis_store.go @@ -131,8 +131,10 @@ func (store *UniversalRedisStore) ListDirectoryPrefixedEntries(ctx context.Conte if prefix == "" { return notPrefixed, nil } + var lastFileName string for count < limit { for _, entry := range notPrefixed { + lastFileName = entry.Name() if strings.HasPrefix(entry.Name(), prefix) { count++ entries = append(entries, entry) @@ -142,10 +144,14 @@ func (store *UniversalRedisStore) ListDirectoryPrefixedEntries(ctx context.Conte break } - notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, startFileName, inclusive, limit) + notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, lastFileName, inclusive, limit) if err != nil { return nil, err } + + if len(notPrefixed) == 0 { + break + } } return entries, nil diff --git a/weed/filer2/redis2/universal_redis_store.go b/weed/filer2/redis2/universal_redis_store.go index 483dd621f..289e85545 100644 --- a/weed/filer2/redis2/universal_redis_store.go +++ b/weed/filer2/redis2/universal_redis_store.go @@ -127,8 +127,10 @@ func (store *UniversalRedis2Store) ListDirectoryPrefixedEntries(ctx context.Cont if prefix == "" { return notPrefixed, nil } + var lastFileName string for count < limit { for _, entry := range notPrefixed { + lastFileName = entry.Name() if strings.HasPrefix(entry.Name(), prefix) { count++ entries = append(entries, entry) @@ -138,10 +140,14 @@ func (store *UniversalRedis2Store) ListDirectoryPrefixedEntries(ctx context.Cont break } - notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, startFileName, inclusive, limit) + notPrefixed, err = store.ListDirectoryEntries(ctx, fullpath, lastFileName, inclusive, limit) if err != nil { return nil, err } + + if len(notPrefixed) == 0 { + break + } } return entries, nil