Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settings: Only call MkdirAll on save #542

Merged
merged 3 commits into from
Jun 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions internal/driver/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ func settingsFileName() (string, error) {
if err != nil {
return "", err
}
dir = filepath.Join(dir, "pprof")
if err := os.MkdirAll(dir, 0755); err != nil {
return "", err
}
return filepath.Join(dir, "settings.json"), nil
return filepath.Join(dir, "pprof", "settings.json"), nil
}

// readSettings reads settings from fname.
Expand Down Expand Up @@ -60,6 +56,14 @@ func writeSettings(fname string, settings *settings) error {
if err != nil {
return fmt.Errorf("could not encode settings: %w", err)
}

// create the settings directory if it does not exist
// XDG specifies permissions 0700 when creating settings dirs:
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
if err := os.MkdirAll(filepath.Dir(fname), 0700); err != nil {
return fmt.Errorf("failed to create settings directory: %w", err)
}

if err := ioutil.WriteFile(fname, data, 0644); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this should have been changed to 0600 too.

return fmt.Errorf("failed to write settings: %w", err)
}
Expand Down