From 70c56f7a180e1113c289574e69dd148bc76db511 Mon Sep 17 00:00:00 2001 From: Aleksey Dmitrevskiy Date: Thu, 14 Mar 2019 18:06:53 +0300 Subject: [PATCH] + app, config: add symlink support, allow to specify absolute path in log_file --- app.go | 6 +++++- config.go | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app.go b/app.go index 18d45b2e..91f4fbdd 100644 --- a/app.go +++ b/app.go @@ -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) } diff --git a/config.go b/config.go index 05888888..b0da6532 100644 --- a/config.go +++ b/config.go @@ -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 }