mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 14:50:55 +03:00
add DirLister interface
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -108,22 +108,24 @@ func (fi *webDavFileInfo) ContentType(_ context.Context) (string, error) {
|
||||
|
||||
// Readdir reads directory entries from the handle
|
||||
func (f *webDavFile) Readdir(_ int) ([]os.FileInfo, error) {
|
||||
return nil, webdav.ErrNotImplemented
|
||||
}
|
||||
|
||||
// ReadDir implements the FileDirLister interface
|
||||
func (f *webDavFile) ReadDir() (webdav.DirLister, error) {
|
||||
if !f.Connection.User.HasPerm(dataprovider.PermListItems, f.GetVirtualPath()) {
|
||||
return nil, f.Connection.GetPermissionDeniedError()
|
||||
}
|
||||
entries, err := f.Connection.ListDir(f.GetVirtualPath())
|
||||
lister, err := f.Connection.ListDir(f.GetVirtualPath())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for idx, info := range entries {
|
||||
entries[idx] = &webDavFileInfo{
|
||||
FileInfo: info,
|
||||
Fs: f.Fs,
|
||||
virtualPath: path.Join(f.GetVirtualPath(), info.Name()),
|
||||
fsPath: f.Fs.Join(f.GetFsPath(), info.Name()),
|
||||
}
|
||||
}
|
||||
return entries, nil
|
||||
return &webDavDirLister{
|
||||
DirLister: lister,
|
||||
fs: f.Fs,
|
||||
virtualDirPath: f.GetVirtualPath(),
|
||||
fsDirPath: f.GetFsPath(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Stat the handle
|
||||
@@ -474,3 +476,24 @@ func (f *webDavFile) Patch(patches []webdav.Proppatch) ([]webdav.Propstat, error
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type webDavDirLister struct {
|
||||
vfs.DirLister
|
||||
fs vfs.Fs
|
||||
virtualDirPath string
|
||||
fsDirPath string
|
||||
}
|
||||
|
||||
func (l *webDavDirLister) Next(limit int) ([]os.FileInfo, error) {
|
||||
files, err := l.DirLister.Next(limit)
|
||||
for idx := range files {
|
||||
info := files[idx]
|
||||
files[idx] = &webDavFileInfo{
|
||||
FileInfo: info,
|
||||
Fs: l.fs,
|
||||
virtualPath: path.Join(l.virtualDirPath, info.Name()),
|
||||
fsPath: l.fs.Join(l.fsDirPath, info.Name()),
|
||||
}
|
||||
}
|
||||
return files, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user