|
|
@@ -32,6 +32,7 @@ type sharedPullerState struct {
|
|
|
curFile protocol.FileInfo // The file as it exists now in our database
|
|
|
sparse bool
|
|
|
created time.Time
|
|
|
+ fsync bool
|
|
|
|
|
|
// Mutable, must be locked for access
|
|
|
err error // The first error we hit
|
|
|
@@ -49,7 +50,7 @@ type sharedPullerState struct {
|
|
|
mut sync.RWMutex // Protects the above
|
|
|
}
|
|
|
|
|
|
-func newSharedPullerState(file protocol.FileInfo, fs fs.Filesystem, folderID, tempName string, blocks []protocol.BlockInfo, reused []int32, ignorePerms, hasCurFile bool, curFile protocol.FileInfo, sparse bool) *sharedPullerState {
|
|
|
+func newSharedPullerState(file protocol.FileInfo, fs fs.Filesystem, folderID, tempName string, blocks []protocol.BlockInfo, reused []int32, ignorePerms, hasCurFile bool, curFile protocol.FileInfo, sparse bool, fsync bool) *sharedPullerState {
|
|
|
return &sharedPullerState{
|
|
|
file: file,
|
|
|
fs: fs,
|
|
|
@@ -67,6 +68,7 @@ func newSharedPullerState(file protocol.FileInfo, fs fs.Filesystem, folderID, te
|
|
|
curFile: curFile,
|
|
|
mut: sync.NewRWMutex(),
|
|
|
sparse: sparse,
|
|
|
+ fsync: fsync,
|
|
|
created: time.Now(),
|
|
|
}
|
|
|
}
|
|
|
@@ -101,13 +103,15 @@ func (w *lockedWriterAt) WriteAt(p []byte, off int64) (n int, err error) {
|
|
|
|
|
|
// SyncClose ensures that no more writes are happening before going ahead and
|
|
|
// syncing and closing the fd, thus needs to acquire a write-lock.
|
|
|
-func (w *lockedWriterAt) SyncClose() error {
|
|
|
+func (w *lockedWriterAt) SyncClose(fsync bool) error {
|
|
|
w.mut.Lock()
|
|
|
defer w.mut.Unlock()
|
|
|
- if err := w.fd.Sync(); err != nil {
|
|
|
- // Sync() is nice if it works but not worth failing the
|
|
|
- // operation over if it fails.
|
|
|
- l.Debugf("fsync failed: %v", err)
|
|
|
+ if fsync {
|
|
|
+ if err := w.fd.Sync(); err != nil {
|
|
|
+ // Sync() is nice if it works but not worth failing the
|
|
|
+ // operation over if it fails.
|
|
|
+ l.Debugf("fsync failed: %v", err)
|
|
|
+ }
|
|
|
}
|
|
|
return w.fd.Close()
|
|
|
}
|
|
|
@@ -303,7 +307,7 @@ func (s *sharedPullerState) finalClose() (bool, error) {
|
|
|
}
|
|
|
|
|
|
if s.writer != nil {
|
|
|
- if err := s.writer.SyncClose(); err != nil && s.err == nil {
|
|
|
+ if err := s.writer.SyncClose(s.fsync); err != nil && s.err == nil {
|
|
|
// This is our error as we weren't errored before.
|
|
|
s.err = err
|
|
|
}
|