aboutsummaryrefslogtreecommitdiff
path: root/config/statefile.go
blob: 22fd21486e9741f6236803b9bc1cefab3d01e904 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package config

import (
	"fmt"
	"log"
	"os"
	"path/filepath"
)

const (
	bareosStateFile = "bareos-fd.9102.state"
	baculaStateFile = "bacula-fd.9102.state"
)

func (c *Config) checkStateFile() {
	// Finds the state file to parse
	if c.stateFile != "" {
		c.stateFile = filepath.Join(c.workDir, c.stateFile)
		info, err := os.Stat(c.stateFile)
		if os.IsNotExist(err) || info.IsDir() {
			fmt.Printf("INFO The state file %s does not exist.\n", c.stateFile)
			os.Exit(0)
		}
	} else {
		c.stateFile = filepath.Join(c.workDir, bareosStateFile)
		info, err := os.Stat(c.stateFile)
		if os.IsNotExist(err) || info.IsDir() {
			c.stateFile = filepath.Join(c.workDir, baculaStateFile)
			info, err = os.Stat(c.stateFile)
			if os.IsNotExist(err) || info.IsDir() {
				fmt.Println("INFO Could not find a suitable state file. Has a job ever run?")
				os.Exit(0)
			}
		}
	}
	if c.verbose {
		log.Println("Using state file ", c.stateFile)
	}
}