summaryrefslogtreecommitdiff
path: root/internal/recordsdir/recordsdir.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-14 11:16:45 +0300
committerPaul Buetow <paul@buetow.org>2026-04-14 11:16:45 +0300
commit2bc4e64acf93f04c8871d964d75f041ada57f89d (patch)
treec156e09a6c65c47e35006a9c108f4a85e78ef1e2 /internal/recordsdir/recordsdir.go
parenta58a6cf092338e0dac45608efa9f2c7b81cbe01f (diff)
refactor: share .records file discovery (ask u3)
Extract ListNonEmptyFiles and HostFromFileName into internal/recordsdir for aggregate and storage ImportFromDir. Behavior unchanged. Made-with: Cursor
Diffstat (limited to 'internal/recordsdir/recordsdir.go')
-rw-r--r--internal/recordsdir/recordsdir.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/recordsdir/recordsdir.go b/internal/recordsdir/recordsdir.go
new file mode 100644
index 0000000..9f3ce5b
--- /dev/null
+++ b/internal/recordsdir/recordsdir.go
@@ -0,0 +1,40 @@
+package recordsdir
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+)
+
+type Entry struct {
+ Path string
+ Host string
+}
+
+func HostFromFileName(name string) string {
+ host := strings.TrimSuffix(name, filepath.Ext(name))
+ if idx := strings.Index(host, "."); idx > 0 {
+ host = host[:idx]
+ }
+ return host
+}
+
+func ListNonEmptyFiles(dir string) ([]Entry, error) {
+ entries, err := os.ReadDir(dir)
+ if err != nil {
+ return nil, err
+ }
+ var out []Entry
+ for _, e := range entries {
+ if e.IsDir() || !strings.HasSuffix(e.Name(), ".records") {
+ continue
+ }
+ path := filepath.Join(dir, e.Name())
+ info, err := os.Stat(path)
+ if err != nil || info.Size() == 0 {
+ continue
+ }
+ out = append(out, Entry{Path: path, Host: HostFromFileName(e.Name())})
+ }
+ return out, nil
+}