summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-09-22 16:22:48 +0300
committerPaul Buetow <paul@buetow.org>2024-09-22 16:22:48 +0300
commitaa1a599f105850e41954ac22de05bf381cfa0d9a (patch)
tree6ae2222d74b82f7cac4f6c94c90b620b723b1070 /internal
parentf0b5e99a7f8c1833e2a936188c2358eab7f78d1d (diff)
can queue
Diffstat (limited to 'internal')
-rw-r--r--internal/oi/oi.go13
-rw-r--r--internal/queue/queue.go2
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
}
}