mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 10:58:55 +00:00
Merge pull request #4021 from greatroar/mac-fsync
backend/local: Ignore ENOTTY for fsync on Mac
This commit is contained in:
commit
7b4fe7bad5
8
changelog/unreleased/issue-4016
Normal file
8
changelog/unreleased/issue-4016
Normal file
@ -0,0 +1,8 @@
|
||||
Bugfix: Support ExFAT-formatted local backends on macOS Ventura
|
||||
|
||||
ExFAT-formatted disks could not be used as local backends starting from macOS
|
||||
Ventura. Restic commands would fail with "inappropriate ioctl for device". This
|
||||
has been fixed.
|
||||
|
||||
https://github.com/restic/restic/issues/4016
|
||||
https://github.com/restic/restic/pull/4021
|
@ -177,7 +177,7 @@ func (b *Local) Save(ctx context.Context, h restic.Handle, rd restic.RewindReade
|
||||
|
||||
// Ignore error if filesystem does not support fsync.
|
||||
err = f.Sync()
|
||||
syncNotSup := errors.Is(err, syscall.ENOTSUP)
|
||||
syncNotSup := err != nil && (errors.Is(err, syscall.ENOTSUP) || isMacENOTTY(err))
|
||||
if err != nil && !syncNotSup {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ package local
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
"github.com/restic/restic/internal/fs"
|
||||
@ -19,7 +20,9 @@ func fsyncDir(dir string) error {
|
||||
}
|
||||
|
||||
err = d.Sync()
|
||||
if errors.Is(err, syscall.ENOTSUP) || errors.Is(err, syscall.ENOENT) || errors.Is(err, syscall.EINVAL) {
|
||||
if err != nil &&
|
||||
(errors.Is(err, syscall.ENOTSUP) || errors.Is(err, syscall.ENOENT) ||
|
||||
errors.Is(err, syscall.EINVAL) || isMacENOTTY(err)) {
|
||||
err = nil
|
||||
}
|
||||
|
||||
@ -31,6 +34,15 @@ func fsyncDir(dir string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// The ExFAT driver on some versions of macOS can return ENOTTY,
|
||||
// "inappropriate ioctl for device", for fsync.
|
||||
//
|
||||
// https://github.com/restic/restic/issues/4016
|
||||
// https://github.com/realm/realm-core/issues/5789
|
||||
func isMacENOTTY(err error) bool {
|
||||
return runtime.GOOS == "darwin" && errors.Is(err, syscall.ENOTTY)
|
||||
}
|
||||
|
||||
// set file to readonly
|
||||
func setFileReadonly(f string, mode os.FileMode) error {
|
||||
return fs.Chmod(f, mode&^0222)
|
||||
|
@ -7,6 +7,9 @@ import (
|
||||
// Can't explicitly flush directory changes on Windows.
|
||||
func fsyncDir(dir string) error { return nil }
|
||||
|
||||
// Windows is not macOS.
|
||||
func isMacENOTTY(err error) bool { return false }
|
||||
|
||||
// We don't modify read-only on windows,
|
||||
// since it will make us unable to delete the file,
|
||||
// and this isn't common practice on this platform.
|
||||
|
Loading…
Reference in New Issue
Block a user