-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cmd/influxd): Add logging work-around for absolute file paths on …
…Windows (#21540)
- Loading branch information
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// +build !windows | ||
|
||
package upgrade | ||
|
||
// Zap only has problems with Windows paths, so this is a no-op on Unix systems. | ||
func (o *logOptions) zapSafeLogPath() (string, error) { | ||
return o.logPath, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package upgrade | ||
|
||
import ( | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
// Work around a bug in zap's handling of absolute paths on Windows. | ||
// See https://github.com/uber-go/zap/issues/621 | ||
|
||
const FakeWindowsScheme = "winfile" | ||
|
||
func init() { | ||
newWinFileSink := func(u *url.URL) (zap.Sink, error) { | ||
// Remove leading slash left by url.Parse() | ||
return os.OpenFile(u.Path[1:], os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644) | ||
} | ||
zap.RegisterSink(FakeWindowsScheme, newWinFileSink) | ||
} | ||
|
||
func (o *logOptions) zapSafeLogPath() (string, error) { | ||
logPath, err := filepath.Abs(o.logPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
return FakeWindowsScheme + ":///" + logPath, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters