summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-05-28 22:35:13 +0300
committerPaul Buetow <paul@buetow.org>2025-05-28 22:35:13 +0300
commit326a1faf9e2aad681c5886c18ab93ee1c99ae24d (patch)
treef0c9f1ece8070600ab4c114480eb8ddf93440e32
parent00d8b2eec47830423cc39c0b2dc403ecd1b1273b (diff)
persisting report to a file as well
-rw-r--r--internal/run.go25
1 files changed, 24 insertions, 1 deletions
diff --git a/internal/run.go b/internal/run.go
index 01f5bae..701d200 100644
--- a/internal/run.go
+++ b/internal/run.go
@@ -2,7 +2,9 @@ package internal
import (
"context"
+ "fmt"
"log"
+ "os"
)
func Run(ctx context.Context, configFile string, renotify, force bool) {
@@ -26,9 +28,30 @@ func Run(ctx context.Context, configFile string, renotify, force bool) {
notifyError(conf, err)
}
- if subject, body, doNotify := state.report(renotify, force); doNotify {
+ subject, body, doNotify := state.report(renotify, force)
+ if doNotify {
if err := notify(conf, subject, body); err != nil {
log.Println("error:", err)
+ return
}
}
+ if err := persistReport(body, conf); err != nil {
+ notifyError(conf, err)
+ }
+}
+
+func persistReport(body string, conf config) error {
+ reportFile := fmt.Sprintf("%s/report.txt", conf.StateDir)
+ tmpFile := fmt.Sprintf("%s.tmp", reportFile)
+
+ f, err := os.Create(tmpFile)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ if _, err = f.WriteString(body); err != nil {
+ return err
+ }
+ return os.Rename(tmpFile, reportFile)
}