From 51c22f4223c668a413f3e5442a9fa626babb27db Mon Sep 17 00:00:00 2001 From: Hristo Trendev Date: Wed, 9 Oct 2019 21:42:15 +0200 Subject: [PATCH] local backend: ignore not supported error on sync() Closes #2395 --- changelog/unreleased/issue-2395 | 12 ++++++++++++ internal/backend/local/local.go | 10 ++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/issue-2395 diff --git a/changelog/unreleased/issue-2395 b/changelog/unreleased/issue-2395 new file mode 100644 index 000000000..548133468 --- /dev/null +++ b/changelog/unreleased/issue-2395 @@ -0,0 +1,12 @@ +Enhancement: Ignore sync errors when operation not supported by local filesystem + +The local backend has been modified to work with filesystems which doesn't support +the `sync` operation. This operation is normally used by restic to ensure that data +files are fully written to disk before continuing. + +For these limited filesystems, saving a file in the backend would previously fail with +an "operation not supported" error. This error is now ignored, which means that e.g. +an SMB mount on macOS can now be used as storage location for a repository. + +https://github.com/restic/restic/issues/2395 +https://forum.restic.net/t/sync-errors-on-mac-over-smb/1859 diff --git a/internal/backend/local/local.go b/internal/backend/local/local.go index 4dbee8a6b..19f083a29 100644 --- a/internal/backend/local/local.go +++ b/internal/backend/local/local.go @@ -5,6 +5,7 @@ import ( "io" "os" "path/filepath" + "syscall" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" @@ -115,8 +116,13 @@ func (b *Local) Save(ctx context.Context, h restic.Handle, rd restic.RewindReade } if err = f.Sync(); err != nil { - _ = f.Close() - return errors.Wrap(err, "Sync") + pathErr, ok := err.(*os.PathError) + isNotSupported := ok && pathErr.Op == "sync" && pathErr.Err == syscall.ENOTSUP + // ignore error if filesystem does not support the sync operation + if !isNotSupported { + _ = f.Close() + return errors.Wrap(err, "Sync") + } } err = f.Close()