log file: if the path is not absolute make it relative to config dir

Also refuse to join invalid file name such as "."

Fixes #85
This commit is contained in:
Nicola Murino
2020-03-03 00:34:06 +01:00
parent df67f4ef34
commit d0a81cabab
9 changed files with 27 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ package cmd
import (
"fmt"
"os"
"path/filepath"
"strconv"
"github.com/drakkan/sftpgo/config"
@@ -140,6 +141,7 @@ func addServeFlags(cmd *cobra.Command) {
func getCustomServeFlags() []string {
result := []string{}
if configDir != defaultConfigDir {
configDir = filepath.Clean(configDir)
result = append(result, "--"+configDirFlag)
result = append(result, configDir)
}
@@ -147,7 +149,10 @@ func getCustomServeFlags() []string {
result = append(result, "--"+configFileFlag)
result = append(result, configFile)
}
if logFilePath != defaultLogFile {
if logFilePath != defaultLogFile && len(logFilePath) > 0 && logFilePath != "." {
if !filepath.IsAbs(logFilePath) {
logFilePath = filepath.Join(configDir, logFilePath)
}
result = append(result, "--"+logFilePathFlag)
result = append(result, logFilePath)
}