From aa1a599f105850e41954ac22de05bf381cfa0d9a Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 22 Sep 2024 16:22:48 +0300 Subject: can queue --- internal/oi/oi.go | 13 ++++++++++++- internal/queue/queue.go | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/oi/oi.go b/internal/oi/oi.go index 00b4dd5..fceafd2 100644 --- a/internal/oi/oi.go +++ b/internal/oi/oi.go @@ -14,6 +14,10 @@ func EnsureDirExists(dir string) error { return nil } +func EnsureParentDirExists(dir string) error { + return EnsureDirExists(filepath.Dir(dir)) +} + func ReadDirFilter(dir string, filter func(file os.DirEntry) bool) (chan string, error) { ch := make(chan string) @@ -72,7 +76,7 @@ func CopyFile(srcPath, dstPath string) error { } defer source.Close() - if err := EnsureDirExists(dstPath); err != nil { + if err := EnsureParentDirExists(dstPath); err != nil { return err } @@ -85,3 +89,10 @@ func CopyFile(srcPath, dstPath string) error { _, err = io.Copy(destination, source) return err } + +func Rename(srcPath, dstPath string) error { + if err := EnsureParentDirExists(dstPath); err != nil { + return err + } + return os.Rename(srcPath, dstPath) +} diff --git a/internal/queue/queue.go b/internal/queue/queue.go index a5ed77c..66b7c38 100644 --- a/internal/queue/queue.go +++ b/internal/queue/queue.go @@ -40,7 +40,7 @@ func queueEntries(args config.Args) error { for filePath := range ch { destPath := fmt.Sprintf("%s/db/%s.%s.queued", args.GosDir, filepath.Base(filePath), now.Format("20060102-150405")) - if err := os.Rename(filePath, destPath); err != nil { + if err := oi.Rename(filePath, destPath); err != nil { return err } } -- cgit v1.2.3