aboutsummaryrefslogtreecommitdiff
path: root/spool.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.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 'spool.go')
-rw-r--r--spool.go70
1 files changed, 0 insertions, 70 deletions
diff --git a/spool.go b/spool.go
deleted file mode 100644
index 071a469..0000000
--- a/spool.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package main
-
-import (
- "encoding/csv"
- "fmt"
- "log"
- "os"
- "path"
- "strconv"
-)
-
-// jobs is a map that matches a job name string to its last successfull run timestamp
-type jobs map[string]uint64
-
-func loadSpool() (entries jobs, err error) {
- var (
- file *os.File
- lines [][]string
- )
- // We read the spool
- file, err = os.Open(path.Join(workDir, spoolFile))
- if err != nil {
- return nil, fmt.Errorf("Couldn't open spool file, starting from scratch: %s", err)
- }
- defer file.Close()
- lines, err = csv.NewReader(file).ReadAll()
- if err != nil {
- return nil, fmt.Errorf("Corrupted spool file, starting from scratch : %s", err)
- }
- if verbose {
- log.Printf("Spool file content : %v\n", lines)
- }
-
- entries = make(map[string]uint64)
- for _, line := range lines {
- var i int
- i, err = strconv.Atoi(line[1])
- if err != nil {
- return nil, fmt.Errorf("Corrupted spool file : couldn't parse timestamp entry")
- }
- entries[line[0]] = uint64(i)
- }
- return
-}
-
-func saveSpool(entries jobs) (err error) {
- var (
- file *os.File
- lines [][]string
- jobName string
- ts uint64
- i int
- )
- file, err = os.Create(path.Join(workDir, spoolFile))
- if err != nil {
- return
- }
- defer file.Close()
-
- lines = make([][]string, len(entries))
- i = 0
- for jobName, ts = range entries {
- lines[i] = make([]string, 2)
- lines[i][0] = jobName
- lines[i][1] = fmt.Sprintf("%d", ts)
- i++
- }
- err = csv.NewWriter(file).WriteAll(lines)
- return
-}