Skip to content

Commit

Permalink
[VAULT-3226] Use os.rename on windows os (#12377) (#12387)
Browse files Browse the repository at this point in the history
* [VAULT-3226] Use os.rename on windows os

* [VAULT-3226] Add changelog
  • Loading branch information
pmmukh authored Aug 20, 2021
1 parent 73b4008 commit 1085049
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog/12377.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note: bug
physical/raft: Fix safeio.Rename error when restoring snapshots on windows
```
17 changes: 15 additions & 2 deletions physical/raft/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math"
"os"
"path/filepath"
"runtime"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 1085049

Please sign in to comment.