From fe0a202dd90005c1e4295ded07142d5a59bdb579 Mon Sep 17 00:00:00 2001 From: Erik Unger Date: Thu, 9 Nov 2023 23:41:44 +0100 Subject: [PATCH] sftpfs and ftpsfs only implement ListDirInfo --- ftpfs/ftpfs.go | 37 ++++++++++--------------------------- sftpfs/sftpfs.go | 37 ++++++++++--------------------------- 2 files changed, 20 insertions(+), 54 deletions(-) diff --git a/ftpfs/ftpfs.go b/ftpfs/ftpfs.go index 108adb8..cd1444e 100644 --- a/ftpfs/ftpfs.go +++ b/ftpfs/ftpfs.go @@ -245,6 +245,16 @@ func (f *FTPFileSystem) ListDirInfo(ctx context.Context, dirPath string, callbac return err } for _, entry := range entries { + if ctx.Err() != nil { + return ctx.Err() + } + match, err := fsimpl.MatchAnyPattern(entry.Name, patterns) + if err != nil { + return err + } + if !match { + continue + } err = callback(entryToFileInfo(entry, f.JoinCleanFile(dirPath, entry.Name))) if err != nil { return err @@ -253,33 +263,6 @@ func (f *FTPFileSystem) ListDirInfo(ctx context.Context, dirPath string, callbac return nil } -func (f *FTPFileSystem) ListDirInfoRecursive(ctx context.Context, dirPath string, callback func(*fs.FileInfo) error, patterns []string) error { - return fmt.Errorf("FTPFileSystem.ListDirInfoRecursive: %w", errors.ErrUnsupported) -} - -func (f *FTPFileSystem) ListDirMax(ctx context.Context, dirPath string, max int, patterns []string) (files []fs.File, err error) { - if max == 0 { - return nil, nil - } - conn, dirPath, release, err := f.getConn(dirPath) - if err != nil { - return nil, err - } - defer release() - - names, err := conn.NameList(dirPath) - if err != nil { - return nil, err - } - for _, name := range names { - files = append(files, f.JoinCleanFile(dirPath, name)) - if max > 0 && len(files) == max { - break - } - } - return files, nil -} - func (f *FTPFileSystem) MatchAnyPattern(name string, patterns []string) (bool, error) { return fsimpl.MatchAnyPattern(name, patterns) } diff --git a/sftpfs/sftpfs.go b/sftpfs/sftpfs.go index 2b8c0d6..480cd25 100644 --- a/sftpfs/sftpfs.go +++ b/sftpfs/sftpfs.go @@ -221,6 +221,16 @@ func (f *SFTPFileSystem) ListDirInfo(ctx context.Context, dirPath string, callba return err } for _, info := range infos { + if ctx.Err() != nil { + return ctx.Err() + } + match, err := fsimpl.MatchAnyPattern(info.Name(), patterns) + if err != nil { + return err + } + if !match { + continue + } err = callback(fs.NewFileInfo(f.JoinCleanFile(dirPath, info.Name()), info, false)) if err != nil { return err @@ -229,33 +239,6 @@ func (f *SFTPFileSystem) ListDirInfo(ctx context.Context, dirPath string, callba return nil } -func (f *SFTPFileSystem) ListDirInfoRecursive(ctx context.Context, dirPath string, callback func(*fs.FileInfo) error, patterns []string) error { - return fmt.Errorf("SFTPFileSystem.ListDirInfoRecursive: %w", errors.ErrUnsupported) -} - -func (f *SFTPFileSystem) ListDirMax(ctx context.Context, dirPath string, max int, patterns []string) (files []fs.File, err error) { - if max == 0 { - return nil, nil - } - client, dirPath, release, err := f.getClient(dirPath) - if err != nil { - return nil, err - } - defer release() - - infos, err := client.ReadDir(dirPath) - if err != nil { - return nil, err - } - for _, info := range infos { - files = append(files, f.JoinCleanFile(dirPath, info.Name())) - if max > 0 && len(files) == max { - break - } - } - return files, nil -} - type sftpFile struct { *sftp.File release func() error