diff options
author | Julien Dessaux | 2020-02-24 23:05:45 +0100 |
---|---|---|
committer | Julien Dessaux | 2020-02-25 09:46:38 +0100 |
commit | cadb15f7afb5e7c88667eb4006209efca17744af (patch) | |
tree | 7e8e9e55c22bd4d195caf2b1dc1123500443ce75 /zabbix/workdir.go | |
parent | Added tests to the spool package, and reworked the code around that. (diff) | |
download | bareos-zabbix-check-cadb15f7afb5e7c88667eb4006209efca17744af.tar.gz bareos-zabbix-check-cadb15f7afb5e7c88667eb4006209efca17744af.tar.bz2 bareos-zabbix-check-cadb15f7afb5e7c88667eb4006209efca17744af.zip |
Added tests to the main package and completely reworked the code around that1.0
Diffstat (limited to '')
-rw-r--r-- | zabbix/workdir.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/zabbix/workdir.go b/zabbix/workdir.go new file mode 100644 index 0000000..287c80a --- /dev/null +++ b/zabbix/workdir.go @@ -0,0 +1,38 @@ +package zabbix + +import ( + "fmt" + "os" + "path/filepath" +) + +const ( + bareosWorkDir = "/var/lib/bareos" + baculaWorkDir = "/var/lib/bacula" +) + +var root = "/" + +// checkWorkDir checks if a work directory is valid +func checkWorkDir() error { + // Determine the work directory to use. + if workDir != "" { + workDir = filepath.Join(root, workDir) + info, err := os.Stat(workDir) + if os.IsNotExist(err) || !info.IsDir() { + return fmt.Errorf("Invalid work directory %s : it does not exist or is not a directory", workDir) + } + } else { + workDir = filepath.Join(root, bareosWorkDir) + info, err := os.Stat(workDir) + if os.IsNotExist(err) || !info.IsDir() { + workDir = filepath.Join(root, baculaWorkDir) + info, err := os.Stat(workDir) + if os.IsNotExist(err) || !info.IsDir() { + return fmt.Errorf("Could not find a suitable work directory. Is bareos or bacula installed?") + } + } + } + workDir = filepath.Clean(workDir) + return nil +} |