Skip to content

Commit

Permalink
Resolve "cannot use os.ReadDir" introduced in PR #665
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Brittan committed Apr 2, 2024
1 parent b7215e4 commit fe38f80
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions filestore.go
Expand Up @@ -19,6 +19,7 @@
package mqtt

import (
"io/fs"
"os"
"path"
"sort"
Expand Down Expand Up @@ -158,15 +159,20 @@ func (store *FileStore) Reset() {
func (store *FileStore) all() []string {
var err error
var keys []string
var files fileInfos

if !store.opened {
ERROR.Println(STR, "trying to use file store, but not open")
return nil
}

files, err = os.ReadDir(store.directory)
entries, err := os.ReadDir(store.directory)
chkerr(err)
files := make(fileInfos, 0, len(entries))
for _, entry := range entries {
info, err := entry.Info()
chkerr(err)
files = append(files, info)
}
sort.Sort(files)
for _, f := range files {
DEBUG.Println(STR, "file in All():", f.Name())
Expand Down Expand Up @@ -245,7 +251,7 @@ func exists(file string) bool {
return true
}

type fileInfos []os.FileInfo
type fileInfos []fs.FileInfo

func (f fileInfos) Len() int {
return len(f)
Expand Down

0 comments on commit fe38f80

Please sign in to comment.