From 108504970c5b75410a33e6796831ddc76b603e0a Mon Sep 17 00:00:00 2001 From: Pratyoy Mukhopadhyay <35388175+pmmukh@users.noreply.github.com> Date: Fri, 20 Aug 2021 07:45:32 -0700 Subject: [PATCH] [VAULT-3226] Use os.rename on windows os (#12377) (#12387) * [VAULT-3226] Use os.rename on windows os * [VAULT-3226] Add changelog --- changelog/12377.txt | 3 +++ physical/raft/snapshot.go | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 changelog/12377.txt diff --git a/changelog/12377.txt b/changelog/12377.txt new file mode 100644 index 0000000000000..d3bd52af24663 --- /dev/null +++ b/changelog/12377.txt @@ -0,0 +1,3 @@ +```release-note: bug +physical/raft: Fix safeio.Rename error when restoring snapshots on windows +``` \ No newline at end of file diff --git a/physical/raft/snapshot.go b/physical/raft/snapshot.go index 9eb9b1e69a4fe..89d5aedba6f13 100644 --- a/physical/raft/snapshot.go +++ b/physical/raft/snapshot.go @@ -9,6 +9,7 @@ import ( "math" "os" "path/filepath" + "runtime" "strings" "sync" "time" @@ -456,7 +457,15 @@ func (s *BoltSnapshotSink) Close() error { // Move the directory into place newPath := strings.TrimSuffix(s.dir, tmpSuffix) - if err := safeio.Rename(s.dir, newPath); err != nil { + + var err error + if runtime.GOOS != "windows" { + err = safeio.Rename(s.dir, newPath) + } else { + err = os.Rename(s.dir, newPath) + } + + if err != nil { s.logger.Error("failed to move snapshot into place", "error", err) return err } @@ -511,7 +520,11 @@ func (i *boltSnapshotInstaller) Install(filename string) error { } // Rename the snapshot to the FSM location - return safeio.Rename(i.filename, filename) + if runtime.GOOS != "windows" { + return safeio.Rename(i.filename, filename) + } else { + return os.Rename(i.filename, filename) + } } // snapshotName generates a name for the snapshot.