summaryrefslogtreecommitdiff
path: root/internal/recordsdir/recordsdir.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/recordsdir/recordsdir.go')
-rw-r--r--internal/recordsdir/recordsdir.go43
1 files changed, 17 insertions, 26 deletions
diff --git a/internal/recordsdir/recordsdir.go b/internal/recordsdir/recordsdir.go
index 94f7f0e..6ebf491 100644
--- a/internal/recordsdir/recordsdir.go
+++ b/internal/recordsdir/recordsdir.go
@@ -6,11 +6,13 @@ import (
"path"
"path/filepath"
"strings"
+ "time"
)
type Entry struct {
- Path string
- Host string
+ Path string
+ Host string
+ ModTime time.Time
}
func HostFromFileName(name string) string {
@@ -21,12 +23,12 @@ func HostFromFileName(name string) string {
return host
}
-func listRecordsFileNames(fsys fs.FS, root string) ([]string, error) {
+func listRecordsFileNames(fsys fs.FS, root string) ([]Entry, error) {
entries, err := fs.ReadDir(fsys, root)
if err != nil {
return nil, err
}
- var names []string
+ var out []Entry
for _, e := range entries {
if e.IsDir() || !strings.HasSuffix(e.Name(), ".records") {
continue
@@ -36,38 +38,27 @@ func listRecordsFileNames(fsys fs.FS, root string) ([]string, error) {
if err != nil || info.Size() == 0 {
continue
}
- names = append(names, e.Name())
+ out = append(out, Entry{
+ Path: rel,
+ Host: HostFromFileName(e.Name()),
+ ModTime: info.ModTime(),
+ })
}
- return names, nil
+ return out, nil
}
// ListNonEmptyFilesFS returns non-empty .records files under root within fsys.
func ListNonEmptyFilesFS(fsys fs.FS, root string) ([]Entry, error) {
- names, err := listRecordsFileNames(fsys, root)
- if err != nil {
- return nil, err
- }
- var out []Entry
- for _, name := range names {
- out = append(out, Entry{
- Path: path.Join(root, name),
- Host: HostFromFileName(name),
- })
- }
- return out, nil
+ return listRecordsFileNames(fsys, root)
}
func ListNonEmptyFiles(dir string) ([]Entry, error) {
- names, err := listRecordsFileNames(os.DirFS(dir), ".")
+ entries, err := listRecordsFileNames(os.DirFS(dir), ".")
if err != nil {
return nil, err
}
- var out []Entry
- for _, name := range names {
- out = append(out, Entry{
- Path: filepath.Join(dir, name),
- Host: HostFromFileName(name),
- })
+ for i := range entries {
+ entries[i].Path = filepath.Join(dir, filepath.Base(entries[i].Path))
}
- return out, nil
+ return entries, nil
}