From bb7b6411b841c95ffd3a7391e47dae5bd38a365e Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Thu, 10 Aug 2017 18:34:22 -0700 Subject: [PATCH] Close file aof before renaming for windows Windows does not allow for renaming files that are use. fixes #211 thanks @icewukong --- controller/aofshrink.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controller/aofshrink.go b/controller/aofshrink.go index eb9add2f..01e93834 100644 --- a/controller/aofshrink.go +++ b/controller/aofshrink.go @@ -263,15 +263,15 @@ func (c *Controller) aofshrink() { // anything below this point is unrecoverable. just log and exit process // back up the live aof, just in case of fatal error + if err := c.f.Close(); err != nil { + log.Fatalf("shink live aof close fatal operation: %v", err) + } if err := os.Rename(path.Join(c.dir, "appendonly.aof"), path.Join(c.dir, "appendonly.bak")); err != nil { log.Fatalf("shink backup fatal operation: %v", err) } if err := os.Rename(path.Join(c.dir, "shrink"), path.Join(c.dir, "appendonly.aof")); err != nil { log.Fatalf("shink rename fatal operation: %v", err) } - if err := c.f.Close(); err != nil { - log.Fatalf("shink live aof close fatal operation: %v", err) - } c.f, err = os.OpenFile(path.Join(c.dir, "appendonly.aof"), os.O_CREATE|os.O_RDWR, 0600) if err != nil { log.Fatalf("shink openfile fatal operation: %v", err)