From bbb866018e968254e91bc9dcd56735adfc186c80 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 21 Oct 2025 14:20:24 +0100 Subject: [PATCH] webdav: add ListP interface - #4788 --- backend/webdav/webdav.go | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/backend/webdav/webdav.go b/backend/webdav/webdav.go index eb7c4dc0d..78e0a825c 100644 --- a/backend/webdav/webdav.go +++ b/backend/webdav/webdav.go @@ -38,6 +38,7 @@ import ( "github.com/rclone/rclone/fs/fserrors" "github.com/rclone/rclone/fs/fshttp" "github.com/rclone/rclone/fs/hash" + "github.com/rclone/rclone/fs/list" "github.com/rclone/rclone/lib/encoder" "github.com/rclone/rclone/lib/pacer" "github.com/rclone/rclone/lib/rest" @@ -888,30 +889,56 @@ func (f *Fs) listAll(ctx context.Context, dir string, directoriesOnly bool, file // This should return ErrDirNotFound if the directory isn't // found. func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err error) { + return list.WithListP(ctx, dir, f) +} + +// ListP lists the objects and directories of the Fs starting +// from dir non recursively into out. +// +// dir should be "" to start from the root, and should not +// have trailing slashes. +// +// This should return ErrDirNotFound if the directory isn't +// found. +// +// It should call callback for each tranche of entries read. +// These need not be returned in any particular order. If +// callback returns an error then the listing will stop +// immediately. +func (f *Fs) ListP(ctx context.Context, dir string, callback fs.ListRCallback) error { + list := list.NewHelper(callback) var iErr error - _, err = f.listAll(ctx, dir, false, false, defaultDepth, func(remote string, isDir bool, info *api.Prop) bool { + _, err := f.listAll(ctx, dir, false, false, defaultDepth, func(remote string, isDir bool, info *api.Prop) bool { if isDir { d := fs.NewDir(remote, time.Time(info.Modified)) // .SetID(info.ID) // FIXME more info from dir? can set size, items? - entries = append(entries, d) + err := list.Add(d) + if err != nil { + iErr = err + return true + } } else { o, err := f.newObjectWithInfo(ctx, remote, info) if err != nil { iErr = err return true } - entries = append(entries, o) + err = list.Add(o) + if err != nil { + iErr = err + return true + } } return false }) if err != nil { - return nil, err + return err } if iErr != nil { - return nil, iErr + return iErr } - return entries, nil + return list.Flush() } // Creates from the parameters passed in a half finished Object which @@ -1634,6 +1661,7 @@ var ( _ fs.Copier = (*Fs)(nil) _ fs.Mover = (*Fs)(nil) _ fs.DirMover = (*Fs)(nil) + _ fs.ListPer = (*Fs)(nil) _ fs.Abouter = (*Fs)(nil) _ fs.Object = (*Object)(nil) )