DirLister: returns appropriate protocol errors
Some checks failed
Code scanning - action / CodeQL-Build (push) Has been cancelled
CI / Test and deploy (push) Has been cancelled
CI / Test build flags (push) Has been cancelled
CI / Test with PgSQL/MySQL/Cockroach (push) Has been cancelled
CI / Build Linux packages (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
Docker / Build (push) Has been cancelled

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino 2024-10-16 19:04:09 +02:00
parent 7d24a4852c
commit 9c744da620
No known key found for this signature in database
GPG key ID: 935D2952DEC4EECF
2 changed files with 8 additions and 10 deletions

View file

@ -322,10 +322,9 @@ func (c *BaseConnection) ListDir(virtualPath string) (*DirListerAt, error) {
} }
return &DirListerAt{ return &DirListerAt{
virtualPath: virtualPath, virtualPath: virtualPath,
user: &c.User, conn: c,
fs: fs,
info: c.User.GetVirtualFoldersInfo(virtualPath), info: c.User.GetVirtualFoldersInfo(virtualPath),
id: c.ID,
protocol: c.protocol,
lister: lister, lister: lister,
}, nil }, nil
} }
@ -1815,10 +1814,9 @@ func (c *BaseConnection) GetFsAndResolvedPath(virtualPath string) (vfs.Fs, strin
// DirListerAt defines a directory lister implementing the ListAt method. // DirListerAt defines a directory lister implementing the ListAt method.
type DirListerAt struct { type DirListerAt struct {
virtualPath string virtualPath string
user *dataprovider.User conn *BaseConnection
fs vfs.Fs
info []os.FileInfo info []os.FileInfo
id string
protocol string
mu sync.Mutex mu sync.Mutex
lister vfs.DirLister lister vfs.DirLister
} }
@ -1861,10 +1859,10 @@ func (l *DirListerAt) Next(limit int) ([]os.FileInfo, error) {
for { for {
files, err := l.lister.Next(limit) files, err := l.lister.Next(limit)
if err != nil && !errors.Is(err, io.EOF) { if err != nil && !errors.Is(err, io.EOF) {
logger.Debug(l.protocol, l.id, "error retrieving directory entries: %+v", err) l.conn.Log(logger.LevelDebug, "error retrieving directory entries: %+v", err)
return files, err return files, l.conn.GetFsError(l.fs, err)
} }
files = l.user.FilterListDir(files, l.virtualPath) files = l.conn.User.FilterListDir(files, l.virtualPath)
if len(l.info) > 0 { if len(l.info) > 0 {
files = slices.Concat(l.info, files) files = slices.Concat(l.info, files)
l.info = nil l.info = nil

View file

@ -1090,7 +1090,7 @@ func TestListerAt(t *testing.T) {
require.ErrorIs(t, err, io.EOF) require.ErrorIs(t, err, io.EOF)
require.Len(t, files, 0) require.Len(t, files, 0)
_, err = lister.Next(-1) _, err = lister.Next(-1)
require.ErrorContains(t, err, "invalid limit") require.ErrorContains(t, err, conn.GetGenericError(err).Error())
err = lister.Close() err = lister.Close()
require.NoError(t, err) require.NoError(t, err)