2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-16 10:05:25 +00:00
restic/internal/fs/fs_helpers.go
2018-06-20 22:53:53 +02:00

46 lines
788 B
Go

package fs
import "os"
// ReadDir reads the directory named by dirname within fs and returns a list of
// directory entries.
func ReadDir(fs FS, dirname string) ([]os.FileInfo, error) {
f, err := fs.Open(dirname)
if err != nil {
return nil, err
}
entries, err := f.Readdir(-1)
if err != nil {
return nil, err
}
err = f.Close()
if err != nil {
return nil, err
}
return entries, nil
}
// ReadDirNames reads the directory named by dirname within fs and returns a
// list of entry names.
func ReadDirNames(fs FS, dirname string) ([]string, error) {
f, err := fs.Open(dirname)
if err != nil {
return nil, err
}
entries, err := f.Readdirnames(-1)
if err != nil {
return nil, err
}
err = f.Close()
if err != nil {
return nil, err
}
return entries, nil
}