list: add WithListP helper to implement List for ListP backends

This commit is contained in:
Nick Craig-Wood
2024-11-25 12:04:29 +00:00
parent cba653d502
commit 37120ef7bd
2 changed files with 74 additions and 1 deletions

View File

@ -1,6 +1,11 @@
package list
import "github.com/rclone/rclone/fs"
import (
"context"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/accounting"
)
// Listing helpers used by backends
@ -41,3 +46,16 @@ func (lh *Helper) Add(entry fs.DirEntry) error {
func (lh *Helper) Flush() error {
return lh.send(1)
}
// WithListP implements the List interface with ListP
//
// It should be used in backends which support ListP to implement
// List.
func WithListP(ctx context.Context, dir string, list fs.ListPer) (entries fs.DirEntries, err error) {
err = list.ListP(ctx, dir, func(newEntries fs.DirEntries) error {
accounting.Stats(ctx).Listed(int64(len(newEntries)))
entries = append(entries, newEntries...)
return nil
})
return entries, err
}