Skip to content

Automatically create the default log directory on Linux if required#21

Closed
danielthatcher wants to merge 3 commits intowincent:masterfrom
danielthatcher:linux-config-dir
Closed

Automatically create the default log directory on Linux if required#21
danielthatcher wants to merge 3 commits intowincent:masterfrom
danielthatcher:linux-config-dir

Conversation

@danielthatcher
Copy link

When installed on Linux clipper will crash on startup when run without any arguments as it can't create a new log file in the default logs directory, which doesn't exist by default:

$ clipper
clipper: 2020/06/15 12:11:02 open /home/daniel/.config/clipper/clipper.json: no such file or directory
clipper: 2020/06/15 12:11:02 open /home/daniel/.config/clipper/logs/clipper.log: no such file or directory

This PR fixes that by recursively creating ~/.config/clipper/logs if it doesn't exist, and if the user hasn't requested a different log file location.

clipper.go Outdated
Comment on lines +211 to +214
if runtime.GOOS == "linux" {
configDir := pathByExpandingTildeInPath(filepath.Dir(defaults.Logfile.value))
os.MkdirAll(configDir, 0700)
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I think this is the wrong place to be executing side-effectful code; this function should really just be about merging settings.

Would you be able to move this down lower, like around here right before we try to open the log file? If you do that, it will additionally take effect for log files which come in via an explicit flag or a config file, which might be a benefit too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed in the latest commit

@wincent wincent closed this in 5cf1566 Jun 16, 2020
@wincent
Copy link
Owner

wincent commented Jun 16, 2020

Thanks @danielthatcher. I squashed this and applied a small tweak on top.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants