Files
seaweedfs/weed/filer/filer_list_recursive.go
T
Chris LuandClaude Opus 5.5 acb7728915 filer: ListEntriesRecursive RPC (#13262)
* filer: name the check that a listing expires an entry

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK

* filer: StreamListRecursiveEntries lists a subtree in path order

It pages through the store's RecursiveLister until the limit, leaves out
and deletes expired entries as a directory listing does, and declines a
subtree in or holding a remote mount.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK

* filer.proto: ListEntriesRecursive

A new RPC rather than a field on ListEntries: a filer that predates it
answers Unimplemented instead of listing one directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK

* filer: serve ListEntriesRecursive

Unimplemented when the store cannot list the subtree in path order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK

* filer: a scoped token is refused ListEntriesRecursive

Classified with TraverseBfsMetadata: it lists a whole subtree, past the
per-directory checks a scoped ListEntries gets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK

* filer: trim a trailing slash before checking a recursive listing for remote mounts

An empty directory lists from the root.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* filer: keep the recursive listing cursor when a page comes back empty

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 12:04:27 -08:00

65 lines
2.0 KiB
Go

package filer
import (
"context"
"fmt"
"strings"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/util"
)
// StreamListRecursiveEntries lists up to limit entries below p in path order
// with the store's RecursiveLister, leaving out expired entries and deleting
// them as a directory listing does. A subtree in or holding a remote mount is
// declined: its directory listings fetch from the remote.
func (f *Filer) StreamListRecursiveEntries(ctx context.Context, p, startPath util.FullPath, prefix string, limit int64, eachEntryFunc ListEachEntryFunc) (lastPath util.FullPath, err error) {
lister, ok := f.Store.(RecursiveLister)
if !ok {
return "", ErrUnsupportedRecursiveListing
}
if p = util.FullPath(strings.TrimSuffix(string(p), "/")); p == "" {
p = "/"
}
if f.RemoteStorage != nil {
for _, mount := range f.RemoteStorage.MountedDirectories() {
if mount == p || mount.IsUnder(p) || p.IsUnder(mount) {
return "", fmt.Errorf("%w: %s is remote mounted", ErrUnsupportedRecursiveListing, mount)
}
}
}
lastPath = startPath
for limit > 0 {
var expiredEntries []*Entry
read, stopped := int64(0), false
page := min(limit, int64(PaginationSize))
var pageLast util.FullPath
pageLast, err = lister.ListRecursivePrefixedEntries(ctx, p, lastPath, prefix, page, func(entry *Entry) (bool, error) {
read++
if ctxErr := ctx.Err(); ctxErr != nil {
return false, ctxErr
}
if listingExpired(entry) {
expiredEntries = append(expiredEntries, entry)
return true, nil
}
limit--
more, eachErr := eachEntryFunc(entry)
stopped = !more || limit == 0
return !stopped, eachErr
})
if pageLast != "" {
lastPath = pageLast
}
for _, entry := range expiredEntries {
if delErr := f.deleteExpiredEntry(ctx, entry.FullPath); delErr != nil {
glog.ErrorfCtx(ctx, "list %s recursively: delete expired %s: %v", p, entry.FullPath, delErr)
}
}
if err != nil || stopped || read < page {
return lastPath, err
}
}
return lastPath, nil
}