Fix #606, Fix #610 [change] app, config: add symlink support, allow to specify absolute path in log_file

This commit is contained in:
Aleksey Dmitrevskiy 2019-03-14 18:06:53 +03:00
parent f857ed74ec
commit e9d20651e9
2 changed files with 13 additions and 3 deletions

6
app.go
View File

@ -288,7 +288,11 @@ func configureLogger(args options) {
} }
} else { } else {
logFilePath := filepath.Join(config.ourWorkingDir, ls.LogFile) logFilePath := filepath.Join(config.ourWorkingDir, ls.LogFile)
file, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0755) if filepath.IsAbs(ls.LogFile) {
logFilePath = ls.LogFile
}
file, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil { if err != nil {
log.Fatalf("cannot create a log file: %s", err) log.Fatalf("cannot create a log file: %s", err)
} }

View File

@ -137,9 +137,15 @@ var config = configuration{
// getConfigFilename returns path to the current config file // getConfigFilename returns path to the current config file
func (c *configuration) getConfigFilename() string { func (c *configuration) getConfigFilename() string {
configFile := config.ourConfigFilename configFile, err := filepath.EvalSymlinks(config.ourConfigFilename)
if err != nil {
if !os.IsNotExist(err) {
log.Error("unexpected error while config file path evaluation: %s", err)
}
configFile = config.ourConfigFilename
}
if !filepath.IsAbs(configFile) { if !filepath.IsAbs(configFile) {
configFile = filepath.Join(config.ourWorkingDir, config.ourConfigFilename) configFile = filepath.Join(config.ourWorkingDir, configFile)
} }
return configFile return configFile
} }