Skip to content

Commit

Permalink
DirLister: returns appropriate protocol errors
Browse files Browse the repository at this point in the history
Signed-off-by: Nicola Murino <[email protected]>
  • Loading branch information
drakkan committed Oct 16, 2024
1 parent 7d24a48 commit 9c744da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions internal/common/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,9 @@ func (c *BaseConnection) ListDir(virtualPath string) (*DirListerAt, error) {
}
return &DirListerAt{
virtualPath: virtualPath,
user: &c.User,
conn: c,
fs: fs,
info: c.User.GetVirtualFoldersInfo(virtualPath),
id: c.ID,
protocol: c.protocol,
lister: lister,
}, nil
}
Expand Down Expand Up @@ -1815,10 +1814,9 @@ func (c *BaseConnection) GetFsAndResolvedPath(virtualPath string) (vfs.Fs, strin
// DirListerAt defines a directory lister implementing the ListAt method.
type DirListerAt struct {
virtualPath string
user *dataprovider.User
conn *BaseConnection
fs vfs.Fs
info []os.FileInfo
id string
protocol string
mu sync.Mutex
lister vfs.DirLister
}
Expand Down Expand Up @@ -1861,10 +1859,10 @@ func (l *DirListerAt) Next(limit int) ([]os.FileInfo, error) {
for {
files, err := l.lister.Next(limit)
if err != nil && !errors.Is(err, io.EOF) {
logger.Debug(l.protocol, l.id, "error retrieving directory entries: %+v", err)
return files, err
l.conn.Log(logger.LevelDebug, "error retrieving directory entries: %+v", 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 {
files = slices.Concat(l.info, files)
l.info = nil
Expand Down
2 changes: 1 addition & 1 deletion internal/common/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ func TestListerAt(t *testing.T) {
require.ErrorIs(t, err, io.EOF)
require.Len(t, files, 0)
_, err = lister.Next(-1)
require.ErrorContains(t, err, "invalid limit")
require.ErrorContains(t, err, conn.GetGenericError(err).Error())
err = lister.Close()
require.NoError(t, err)

Expand Down

0 comments on commit 9c744da

Please sign in to comment.