ensure close file before rename bookmark file.

pull/849/head
runner.mei 2014-08-19 09:57:39 +08:00
parent aa4f2363b0
commit 45c1afa6c1
1 changed files with 4 additions and 2 deletions

View File

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