aboutsummaryrefslogtreecommitdiff
path: root/spool/save.go
diff options
context:
space:
mode:
authorJulien Dessaux2020-01-30 17:44:42 +0100
committerJulien Dessaux2020-01-30 17:44:42 +0100
commitbea8e5aba8fc84dcb0c980c3948ed6d78719dded (patch)
treef84f2722b98f4c2996b64ce24ac322c9709617ed /spool/save.go
parentDocument where C structures for state file header and job entry come from (diff)
downloadbareos-zabbix-check-bea8e5aba8fc84dcb0c980c3948ed6d78719dded.tar.gz
bareos-zabbix-check-bea8e5aba8fc84dcb0c980c3948ed6d78719dded.tar.bz2
bareos-zabbix-check-bea8e5aba8fc84dcb0c980c3948ed6d78719dded.zip
Big rafactoring : code split in several modules and some other best practices
Diffstat (limited to '')
-rw-r--r--spool/save.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/spool/save.go b/spool/save.go
new file mode 100644
index 0000000..b01dc7b
--- /dev/null
+++ b/spool/save.go
@@ -0,0 +1,28 @@
+package spool
+
+import (
+ "encoding/csv"
+ "fmt"
+ "os"
+ "path"
+)
+
+// Save writes a spool on the disk
+func (s *Spool) Save() (err error) {
+ file, err := os.Create(path.Join(s.config.WorkDir(), spoolFile))
+ if err != nil {
+ return
+ }
+ defer file.Close()
+
+ lines := make([][]string, len(s.jobs))
+ var i int = 0
+ for _, job := range s.jobs {
+ lines[i] = make([]string, 2)
+ lines[i][0] = job.Name
+ lines[i][1] = fmt.Sprintf("%d", job.Timestamp)
+ i++
+ }
+ err = csv.NewWriter(file).WriteAll(lines)
+ return
+}