Skip to content

Commit

Permalink
better crash recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
keks committed Oct 29, 2018
1 parent 9546f7b commit 3af502d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ func Save(f *os.File, v interface{}) error {
return errors.Wrapf(err, "error marshaling value of type %T", v)
}

_, err = f.Seek(0, 0)
if err != nil {
return errors.Wrap(err, "error seeking to beginning of file")
}

err = f.Truncate(0)
if err != nil {
return errors.Wrap(err, "error truncating file")
}

_, err = f.Write(data)
if err != nil {
return errors.Wrap(err, "error copying data into file")
Expand Down

0 comments on commit 3af502d

Please sign in to comment.