configfile: fall back to sync() if fsync() fails

This can happen on network drives: FRITZ.NAS mounted on MacOS returns
"operation not supported": https://github.com/rfjakob/gocryptfs/issues/390
This commit is contained in:
Jakob Unterwurzacher 2019-04-07 22:04:21 +02:00
parent 7d1400d872
commit 8459bb15c1
1 changed files with 6 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"syscall"
"github.com/rfjakob/gocryptfs/internal/contentenc" "github.com/rfjakob/gocryptfs/internal/contentenc"
"github.com/rfjakob/gocryptfs/internal/cryptocore" "github.com/rfjakob/gocryptfs/internal/cryptocore"
@ -285,7 +286,11 @@ func (cf *ConfFile) WriteFile() error {
} }
err = fd.Sync() err = fd.Sync()
if err != nil { if err != nil {
return err // This can happen on network drives: FRITZ.NAS mounted on MacOS returns
// "operation not supported": https://github.com/rfjakob/gocryptfs/issues/390
tlog.Warn.Printf("Warning: fsync failed: %v", err)
// Try sync instead
syscall.Sync()
} }
err = fd.Close() err = fd.Close()
if err != nil { if err != nil {