Merge pull request #66 from maximbaz/truncate_config_files_before_writing

Prevent file corruption by truncating the files
This commit is contained in:
J Guerreiro authored and GitHub committed 2017-11-21 13:31:16 +09:00
commit 324ff366bc
2 files changed
+2 -2

No files matched your search

+1 -1
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
}
+1 -1
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
}