Skip to content

Commit d3b68f6

Browse files
committed
refactor: make log file directory on all platforms
I don't see any reason why this should be limited to Linux, so remove the platform check. Additionally, check the error condition and blow up if we can't make the directory. Finally, remove "config" from the variable name because it may not be a `~/.config` directory at all. And finally, avoid calling `expandPath` twice.
1 parent 28819e0 commit d3b68f6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

clipper.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ func main() {
266266
// Merge flags -> config -> defaults.
267267
mergeSettings()
268268

269-
if runtime.GOOS == "linux" {
270-
configDir := expandPath(filepath.Dir(settings.Logfile.value))
271-
os.MkdirAll(configDir, 0700)
272-
}
273269
expandedPath := expandPath(settings.Logfile.value)
270+
logDir := filepath.Dir(expandedPath)
271+
if err := os.MkdirAll(logDir, 0700); err != nil {
272+
log.Fatal(err)
273+
}
274274
outfile, err := os.OpenFile(expandedPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
275275
if err != nil {
276276
log.Fatal(err)

0 commit comments

Comments
 (0)