From 34d0f372fd510f9db88583548195718a4841d392 Mon Sep 17 00:00:00 2001 From: Maxim Baz Date: Tue, 21 Nov 2017 00:41:55 +0100 Subject: [PATCH] Prevent file corruption by truncating the files --- config.go | 2 +- vcs.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index d612cb0d..cde1d4b4 100644 --- a/config.go +++ b/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 } diff --git a/vcs.go b/vcs.go index b9d0082b..11622c71 100644 --- a/vcs.go +++ b/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 }