mirror of
https://github.com/rclone/rclone.git
synced 2025-08-13 23:38:51 +02:00
list: add WithListP helper to implement List for ListP backends
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user