Skip to content

Commit

Permalink
[VAULT-3226] Use os.rename on windows os (#12377) (#12381)
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 committed Aug 19, 2021
1 parent 9222923 commit 51c3aa3
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
@@ -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
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 51c3aa3

Please sign in to comment.