From db576ba636fe5a583a20aa534210dbef0fcbfdc6 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 5 Feb 2014 11:21:35 -0500 Subject: [PATCH] Close account files before renaming, instead of deferring. Fixes file locking issues on Windows. --- disksync.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/disksync.go b/disksync.go index 2d5a85c..d643457 100644 --- a/disksync.go +++ b/disksync.go @@ -377,13 +377,15 @@ func (a *Account) writeWallet(dir string) error { if err != nil { return err } - defer tmpfile.Close() if _, err = a.Wallet.WriteTo(tmpfile); err != nil { return err } - if err = Rename(tmpfile.Name(), wfilepath); err != nil { + tmppath := tmpfile.Name() + tmpfile.Close() + + if err = Rename(tmppath, wfilepath); err != nil { return err } @@ -397,13 +399,15 @@ func (a *Account) writeTxStore(dir string) error { if err != nil { return err } - defer tmpfile.Close() if _, err = a.TxStore.WriteTo(tmpfile); err != nil { return err } - if err = Rename(tmpfile.Name(), txfilepath); err != nil { + tmppath := tmpfile.Name() + tmpfile.Close() + + if err = Rename(tmppath, txfilepath); err != nil { return err } @@ -417,13 +421,15 @@ func (a *Account) writeUtxoStore(dir string) error { if err != nil { return err } - defer tmpfile.Close() if _, err = a.UtxoStore.WriteTo(tmpfile); err != nil { return err } - if err = Rename(tmpfile.Name(), utxofilepath); err != nil { + tmppath := tmpfile.Name() + tmpfile.Close() + + if err = Rename(tmppath, utxofilepath); err != nil { return err }