From 45c1afa6c1d741545d16be3c81d9737aeca14bcb Mon Sep 17 00:00:00 2001 From: "runner.mei" Date: Tue, 19 Aug 2014 09:57:39 +0800 Subject: [PATCH] ensure close file before rename bookmark file. --- wal/global_state.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wal/global_state.go b/wal/global_state.go index 3eea577bf6..36fd6c4e17 100644 --- a/wal/global_state.go +++ b/wal/global_state.go @@ -40,7 +40,7 @@ type oldGlobalState struct { func newGlobalState(path string) (*GlobalState, error) { f, err := os.Open(path) - if err != nil { + if err == nil { defer f.Close() } @@ -83,7 +83,9 @@ func (self *GlobalState) writeToFile() error { return err } - os.Remove(self.path) + if err := os.Remove(self.path); nil != err && !os.IsNotExist(err) { + return err + } return os.Rename(self.path+".new", self.path) }