mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-10 13:20:33 +02:00
cmd/cli: only cleanup log file if set
Otherwise, normalizeLogFilePath may return incorrect log file path, causing invalid log file/backup initialization. Thus "--cleanup" will complain about invalid files.
This commit is contained in:
+8
-7
@@ -685,13 +685,14 @@ NOTE: Uninstalling will set DNS to values provided by DHCP.`,
|
|||||||
var files []string
|
var files []string
|
||||||
// Config file.
|
// Config file.
|
||||||
files = append(files, v.ConfigFileUsed())
|
files = append(files, v.ConfigFileUsed())
|
||||||
// Log file.
|
// Log file and backup log file.
|
||||||
logFile := normalizeLogFilePath(cfg.Service.LogPath)
|
// For safety, only process if log file path is absolute.
|
||||||
files = append(files, logFile)
|
if logFile := normalizeLogFilePath(cfg.Service.LogPath); filepath.IsAbs(logFile) {
|
||||||
// Backup log file.
|
files = append(files, logFile)
|
||||||
oldLogFile := logFile + oldLogSuffix
|
oldLogFile := logFile + oldLogSuffix
|
||||||
if _, err := os.Stat(oldLogFile); err == nil {
|
if _, err := os.Stat(oldLogFile); err == nil {
|
||||||
files = append(files, oldLogFile)
|
files = append(files, oldLogFile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Socket files.
|
// Socket files.
|
||||||
if dir, _ := socketDir(); dir != "" {
|
if dir, _ := socketDir(); dir != "" {
|
||||||
|
|||||||
+2
-5
@@ -67,11 +67,8 @@ func Main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func normalizeLogFilePath(logFilePath string) string {
|
func normalizeLogFilePath(logFilePath string) string {
|
||||||
// In cleanup mode, we always want the full log file path.
|
if logFilePath == "" || filepath.IsAbs(logFilePath) || service.Interactive() {
|
||||||
if !cleanup {
|
return logFilePath
|
||||||
if logFilePath == "" || filepath.IsAbs(logFilePath) || service.Interactive() {
|
|
||||||
return logFilePath
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if homedir != "" {
|
if homedir != "" {
|
||||||
return filepath.Join(homedir, logFilePath)
|
return filepath.Join(homedir, logFilePath)
|
||||||
|
|||||||
Reference in New Issue
Block a user