diff options
| author | Paul Buetow <paul@buetow.org> | 2024-10-02 10:46:00 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-10-02 10:46:00 +0300 |
| commit | a93d91223724b94480b7166970ede97d8d190bdb (patch) | |
| tree | 14e3552c5713d4a7b3d2602d8567ab11785c2906 | |
| parent | bc6a3e478a7e0efc12c30be9f74ef5c3ff7a63fb (diff) | |
refactor
| -rw-r--r-- | internal/oi/oi.go | 2 | ||||
| -rw-r--r-- | internal/queue/queue.go | 21 |
2 files changed, 14 insertions, 9 deletions
diff --git a/internal/oi/oi.go b/internal/oi/oi.go index c6b569f..967109d 100644 --- a/internal/oi/oi.go +++ b/internal/oi/oi.go @@ -59,7 +59,6 @@ func TraverseDir(dir string, cb func(file os.DirEntry) error) error { } var errs []error - for _, file := range files { if err := cb(file); err != nil { errs = append(errs, err) @@ -85,6 +84,7 @@ func ReadDirSlurp[T any](dir string, cb func(file os.DirEntry) (T, bool)) ([]T, return results, nil } +// Rename to ReadDirRandom func ReadDirRandomEntry[T any](dir string, cb func(file os.DirEntry) (T, bool)) (T, error) { results, err := ReadDirSlurp(dir, cb) diff --git a/internal/queue/queue.go b/internal/queue/queue.go index e14ff90..94ea1e0 100644 --- a/internal/queue/queue.go +++ b/internal/queue/queue.go @@ -29,9 +29,10 @@ func queueEntries(args config.Args) error { // Strictly, we only operate on .txt files, but we also accept .md as Obsidian creates only .md files. var validExtensions = []string{".txt", ".md"} - ch, err := oi.ReadDirFilter(args.GosDir, func(entry os.DirEntry) bool { - return slices.Contains(validExtensions, filepath.Ext(entry.Name())) && - entry.Type().IsRegular() + ch, err := oi.ReadDirFilter(args.GosDir, func(file os.DirEntry) (string, bool) { + filePath := filepath.Join(args.GosDir, file.Name()) + return filePath, slices.Contains(validExtensions, filepath.Ext(file.Name())) && + file.Type().IsRegular() }) if err != err { return err @@ -52,9 +53,10 @@ func queueEntries(args config.Args) error { // Queue all ./db/queued/*.txt.STAMP.queued into ./db/platforms/PLATFORM/*.txt.STAMP.queued // for each PLATFORM func queuePlatforms(args config.Args) error { - dbDir := fmt.Sprintf("%s/db", args.GosDir) - ch, err := oi.ReadDirFilter(dbDir, func(entry os.DirEntry) bool { - return strings.HasSuffix(entry.Name(), ".queued") + dbDir := filepath.Join(args.GosDir, "db") + ch, err := oi.ReadDirFilter(dbDir, func(file os.DirEntry) (string, bool) { + filePath := filepath.Join(dbDir, file.Name()) + return filePath, strings.HasSuffix(file.Name(), ".queued") }) if err != err { return err @@ -70,6 +72,7 @@ func queuePlatforms(args config.Args) error { if err := os.Remove(filePath); err != nil { return err } + } return nil @@ -77,8 +80,10 @@ func queuePlatforms(args config.Args) error { // Queue ./db/queued/*.txt.STAMP.queued to ./db/platforms/PLATFORM/*.txt.STAMP.queued func queuePlatform(entryPath, gosDir, platform string) error { - destDir := fmt.Sprintf("%s/db/platforms/%s/", gosDir, strings.ToLower(platform)) - destPath := fmt.Sprintf("%s/%s", destDir, filepath.Base(entryPath)) + destDir := filepath.Join(gosDir, "db/platform", strings.ToLower(platform)) + // destDir := fmt.Sprintf("%s/db/platforms/%s/", gosDir, strings.ToLower(platform)) + destPath := filepath.Join(destDir, filepath.Base(entryPath)) + // destPath := fmt.Sprintf("%s/%s", destDir, filepath.Base(entryPath)) postedFile := fmt.Sprintf("%s.posted", strings.TrimSuffix(destPath, ".queued")) // Entry already posted platform? |
