Skip to content

Commit

Permalink
Fix #606, Fix #610 [change] app, config: add symlink support, allow t…
Browse files Browse the repository at this point in the history
…o specify absolute path in log_file
  • Loading branch information
Aleksey Dmitrevskiy committed Mar 14, 2019
1 parent f857ed7 commit e9d2065
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ func configureLogger(args options) {
}
} else {
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 {
log.Fatalf("cannot create a log file: %s", err)
}
Expand Down
10 changes: 8 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,15 @@ var config = configuration{

// getConfigFilename returns path to the current config file
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) {
configFile = filepath.Join(config.ourWorkingDir, config.ourConfigFilename)
configFile = filepath.Join(config.ourWorkingDir, configFile)
}
return configFile
}
Expand Down

0 comments on commit e9d2065

Please sign in to comment.