-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsetconfpath_linux.go
41 lines (32 loc) · 1.13 KB
/
setconfpath_linux.go
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
40
41
package main
import (
"os"
"path/filepath"
)
var logFileName = "nzb-monkey-go.log"
var logFilePath = filepath.Join("/tmp", logFileName)
var confPath string
func setConfPath() {
oldConfFile := filepath.Join(appPath, "config.txt")
confDir := filepath.Join(homePath, ".config")
confFile := filepath.Join(confDir, "nzb-monkey-go.conf")
if args.Config != "" {
// use config file from arguments if provided
confPath = filepath.Clean(args.Config)
} else {
confPath = confFile
// make sure the directory for the config file exists, otherwise the config file cannot be saved
if err := os.MkdirAll(confDir, os.ModePerm); err != nil {
Log.Error("Error creating config dir %s: %s", confDir, err.Error())
exit(1)
}
if _, err := os.Stat(oldConfFile); err == nil {
// if config.txt in the application path already exists move it to the new place
Log.Info("Old config file detected. Moving config file from %s to %s", oldConfFile, confFile)
if err := os.Rename(oldConfFile, confFile); err != nil {
Log.Error("Error while moving config file from %s to %s: %s", oldConfFile, confFile, err.Error())
exit(1)
}
}
}
}