Browse Source

Prevent file corruption by truncating the files

Maxim Baz 7 years ago
parent
commit
34d0f372fd
2 changed files with 2 additions and 2 deletions
  1. 1 1
      config.go
  2. 1 1
      vcs.go

+ 1 - 1
config.go

@@ -87,7 +87,7 @@ func readAlpmConfig(pacmanconf string) (conf alpm.PacmanConfig, err error) {
 func (config *Configuration) saveConfig() error {
 	config.NoConfirm = false
 	marshalledinfo, _ := json.MarshalIndent(config, "", "\t")
-	in, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE, 0644)
+	in, err := os.OpenFile(configFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
 	if err != nil {
 		return err
 	}

+ 1 - 1
vcs.go

@@ -129,7 +129,7 @@ func saveVCSInfo() error {
 	if err != nil || string(marshalledinfo) == "null" {
 		return err
 	}
-	in, err := os.OpenFile(vcsFile, os.O_RDWR|os.O_CREATE, 0644)
+	in, err := os.OpenFile(vcsFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
 	if err != nil {
 		return err
 	}