webdav: remove File.Readdir, add FileSystem.Readdir

References: https://github.com/emersion/go-webdav/issues/15
This commit is contained in:
Simon Ser 2020-01-21 19:59:09 +01:00
parent e851e6e3f1
commit 4e4a5abed2
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 15 additions and 8 deletions

View File

@ -39,4 +39,17 @@ func (fs LocalFileSystem) Stat(name string) (os.FileInfo, error) {
return os.Stat(p)
}
func (fs LocalFileSystem) Readdir(name string) ([]os.FileInfo, error) {
p, err := fs.path(name)
if err != nil {
return nil, err
}
f, err := os.Open(p)
if err != nil {
return nil, err
}
defer f.Close()
return f.Readdir(-1)
}
var _ FileSystem = LocalFileSystem("")

View File

@ -15,12 +15,12 @@ type File interface {
io.Closer
io.Reader
io.Seeker
Readdir(count int) ([]os.FileInfo, error)
}
type FileSystem interface {
Open(name string) (File, error)
Stat(name string) (os.FileInfo, error)
Readdir(name string) ([]os.FileInfo, error)
}
type Handler struct {
@ -109,13 +109,7 @@ func (b *backend) propfind(propfind *internal.Propfind, name string, fi os.FileI
childDepth = internal.DepthZero
}
f, err := b.FileSystem.Open(name)
if err != nil {
return err
}
defer f.Close()
children, err := f.Readdir(-1)
children, err := b.FileSystem.Readdir(name)
if err != nil {
return err
}