Skip to content

Commit

Permalink
Merge pull request #670 from planetscale/nickvanw/make-config-dir
Browse files Browse the repository at this point in the history
Attempt `os.MkdirAll` for the config-file if we fallback from Keychain
  • Loading branch information
nickvanw authored Apr 28, 2023
2 parents c239ad2 + 5c62bb1 commit 1e30660
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,24 @@ func deleteAccessTokenPath() error {
return nil
}

func writeAccessTokenPath(accessToken string) error {
func writeAccessTokenPath(accessToken string) error {
tokenPath, err := accessTokenPath()
if err != nil {
return err
}

configDir := filepath.Dir(tokenPath)

_, err = os.Stat(configDir)
if os.IsNotExist(err) {
err := os.MkdirAll(configDir, 0771)
if err != nil {
return errors.New("error creating config directory")
}
} else if err != nil {
return err
}

tokenBytes := []byte(accessToken)
err = os.WriteFile(tokenPath, tokenBytes, tokenFileMode)
if err != nil {
Expand Down

0 comments on commit 1e30660

Please sign in to comment.