Prevent file corruption by truncating the files

This commit is contained in:
Maxim Baz 2017-11-21 00:41:55 +01:00
parent 878c606556
commit 34d0f372fd
No known key found for this signature in database
GPG key ID: 011FDC52DA839335
2 changed files with 2 additions and 2 deletions

View file

@ -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
}

2
vcs.go
View file

@ -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
}