Skip to content

Commit

Permalink
Truncate config.json before writing
Browse files Browse the repository at this point in the history
Fixes #58
  • Loading branch information
breml committed Mar 19, 2021
1 parent 7736d84 commit 13292f2
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func CheckAndLoad() error {
return fmt.Errorf("Error creating config directory [%v]", err)
}

f, err := os.OpenFile(filepath.Join(configDir, "config.json"), os.O_RDWR|os.O_CREATE, 0666)
f, err := os.OpenFile(filepath.Join(configDir, "config.json"), os.O_RDWR|os.O_CREATE, 0600)
if err != nil && !os.IsNotExist(err) {
return err
}
Expand Down Expand Up @@ -64,17 +64,15 @@ func CheckAndLoad() error {
log.Debugf("Download path set to %s", cfg.DefaultPath)

return nil

}

func Get() *config {
return &cfg
}

//UpsertBinary adds or updats an existing
//binary resource in the config
// UpsertBinary adds or updats an existing
// binary resource in the config
func UpsertBinary(c *Binary) error {

if c != nil {
cfg.Bins[c.Path] = c
err := write()
Expand All @@ -98,7 +96,7 @@ func RemoveBinaries(paths []string) error {

func write() error {
home, err := os.UserHomeDir()
f, err := os.OpenFile(filepath.Join(home, ".bin", "config.json"), os.O_RDWR|os.O_CREATE, 0666)
f, err := os.OpenFile(filepath.Join(home, ".bin", "config.json"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}
Expand All @@ -119,8 +117,8 @@ func write() error {
func GetArch() []string {
res := []string{runtime.GOARCH}
if runtime.GOARCH == "amd64" {
//Adding x86_64 manually since the uname syscall (man 2 uname)
//is not implemented in all systems
// Adding x86_64 manually since the uname syscall (man 2 uname)
// is not implemented in all systems
res = append(res, "x86_64")
res = append(res, "x64")
res = append(res, "64")
Expand Down

0 comments on commit 13292f2

Please sign in to comment.