Skip to content

Commit

Permalink
Merge pull request #6454 from sinsharat/windows_save_snapshot_fix
Browse files Browse the repository at this point in the history
ctlv3: close snapshot file before rename (Windows)
  • Loading branch information
xiang90 authored Sep 16, 2016
2 parents 0d65061 + fef6557 commit 86aeeca
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion etcdctl/ctlv3/command/snapshot_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func snapshotSaveCommandFunc(cmd *cobra.Command, args []string) {

partpath := path + ".part"
f, err := os.Create(partpath)
defer f.Close()

if err != nil {
exiterr := fmt.Errorf("could not open %s (%v)", partpath, err)
ExitWithError(ExitBadArgs, exiterr)
Expand All @@ -134,6 +134,8 @@ func snapshotSaveCommandFunc(cmd *cobra.Command, args []string) {

fileutil.Fsync(f)

f.Close()

if rerr := os.Rename(partpath, path); rerr != nil {
exiterr := fmt.Errorf("could not rename %s to %s (%v)", partpath, path, rerr)
ExitWithError(ExitIO, exiterr)
Expand Down

0 comments on commit 86aeeca

Please sign in to comment.