Skip to content

Commit

Permalink
Merge pull request hashicorp#242 from hashicorp/issue_241
Browse files Browse the repository at this point in the history
Disable parent directory fsync on windows
  • Loading branch information
preetapan authored Aug 24, 2017
2 parents ac70407 + 7b31628 commit 3b4d64b
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions file_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -391,17 +392,18 @@ func (s *FileSnapshotSink) Close() error {
return err
}

// fsync the parent directory, to sync directory edits to disk
parentFH, err := os.Open(s.parentDir)
defer parentFH.Close()
if err != nil {
s.logger.Printf("[ERR] snapshot: Failed to open snapshot parent directory %v, error: %v", s.parentDir, err)
return err
}
if runtime.GOOS != "windows" { //skipping fsync for directory entry edits on Windows, only needed for *nix style file systems
parentFH, err := os.Open(s.parentDir)
defer parentFH.Close()
if err != nil {
s.logger.Printf("[ERR] snapshot: Failed to open snapshot parent directory %v, error: %v", s.parentDir, err)
return err
}

if err = parentFH.Sync(); err != nil {
s.logger.Printf("[ERR] snapshot: Failed syncing parent directory %v, error: %v", s.parentDir, err)
return err
if err = parentFH.Sync(); err != nil {
s.logger.Printf("[ERR] snapshot: Failed syncing parent directory %v, error: %v", s.parentDir, err)
return err
}
}

// Reap any old snapshots
Expand Down

0 comments on commit 3b4d64b

Please sign in to comment.