diff --git a/internal/config/config.go b/internal/config/config.go index d69da6cf..48c157b3 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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" @@ -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 } diff --git a/internal/config/writefile.go b/internal/config/writefile.go new file mode 100644 index 00000000..cfc7e9b8 --- /dev/null +++ b/internal/config/writefile.go @@ -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) +} diff --git a/internal/config/writefile_windows.go b/internal/config/writefile_windows.go new file mode 100644 index 00000000..1845f483 --- /dev/null +++ b/internal/config/writefile_windows.go @@ -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) +}