diff options
author | Julien Dessaux | 2020-01-30 17:44:42 +0100 |
---|---|---|
committer | Julien Dessaux | 2020-01-30 17:44:42 +0100 |
commit | bea8e5aba8fc84dcb0c980c3948ed6d78719dded (patch) | |
tree | f84f2722b98f4c2996b64ce24ac322c9709617ed /config/workdir.go | |
parent | Document where C structures for state file header and job entry come from (diff) | |
download | bareos-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 'config/workdir.go')
-rw-r--r-- | config/workdir.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/config/workdir.go b/config/workdir.go new file mode 100644 index 0000000..283fdc5 --- /dev/null +++ b/config/workdir.go @@ -0,0 +1,40 @@ +package config + +import ( + "fmt" + "log" + "os" + "path" +) + +const ( + bareosWorkDir = "/var/lib/bareos" + baculaWorkDir = "/var/lib/bacula" +) + +// checkWorkDir checks if a work directory is valid +func (c *Config) checkWorkDir() { + // Determine the work directory to use. + if c.workDir != "" { + info, err := os.Stat(c.workDir) + if os.IsNotExist(err) || !info.IsDir() { + fmt.Printf("INFO Invalid work directory %s : it does not exist or is not a directory.\n", c.workDir) + os.Exit(0) + } + } else { + c.workDir = bareosWorkDir + info, err := os.Stat(c.workDir) + if os.IsNotExist(err) || !info.IsDir() { + c.workDir = baculaWorkDir + info, err := os.Stat(c.workDir) + if os.IsNotExist(err) || !info.IsDir() { + fmt.Println("INFO Could not find a suitable work directory. Is bareos or bacula installed?") + os.Exit(0) + } + } + } + c.workDir = path.Clean(c.workDir) + if c.verbose { + log.Println("Setting work directory to ", c.workDir) + } +} |