Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

fix(config): Use ioutil.WriteFile on Windows #212

Merged
merged 1 commit into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/profclems/glab/internal/manip"

"github.com/google/renameio"
"github.com/logrusorgru/aurora"
"github.com/spf13/cobra"
"github.com/tcnksm/go-gitconfig"
Expand Down Expand Up @@ -159,7 +158,7 @@ func SetEnv(key, value string) {
newData += newConfig
}
_ = os.MkdirAll(filepath.Join(cFile, ".."), 0755)
if err = renameio.WriteFile(cFile, []byte(newData), 0666); err != nil {
if err = WriteFile(cFile, []byte(newData), 0600); err != nil {
log.Println("Failed to update config file:", err)
return
}
Expand Down
13 changes: 13 additions & 0 deletions internal/config/writefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build !windows

package config

import (
"os"

"github.com/google/renameio"
)

func WriteFile(filename string, data []byte, perm os.FileMode) error {
return renameio.WriteFile(filename, data, perm)
}
13 changes: 13 additions & 0 deletions internal/config/writefile_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package config

import (
"os"
"io/ioutil"
)

// Note: this is not atomic, but apparently there's no way to atomically
// replace a file on windows which is why renameio doesn't support
// windows.
func WriteFile(filename string, data []byte, perm os.FileMode) error {
return ioutil.WriteFile(filename, data, perm)
}