diff --git a/changelog/unreleased/pull-21796 b/changelog/unreleased/pull-21796 index 1d559f9d7..d0a259695 100644 --- a/changelog/unreleased/pull-21796 +++ b/changelog/unreleased/pull-21796 @@ -1,6 +1,8 @@ Change: Update dependencies and require Go 1.25 or newer We have updated all dependencies. Restic now requires Go 1.25 or newer to build. +In addition, the Windows build of restic using Go 1.26 was fixed. https://github.com/restic/restic/pull/21796 https://github.com/restic/restic/pull/5619 +https://github.com/restic/restic/issues/21791 diff --git a/internal/fs/const_unix.go b/internal/fs/const_unix.go index b75387394..7c989bc60 100644 --- a/internal/fs/const_unix.go +++ b/internal/fs/const_unix.go @@ -9,3 +9,9 @@ const O_NOFOLLOW int = syscall.O_NOFOLLOW // O_DIRECTORY instructs the kernel to only open directories. const O_DIRECTORY int = syscall.O_DIRECTORY + +// sanitizeFlags cleans up flags that conflict with actual OS API flags. +// Must only be used right before passing the flags to the go stdlib. +func sanitizeFlags(flags int) int { + return flags +} diff --git a/internal/fs/const_windows.go b/internal/fs/const_windows.go index 8e7aebf6c..1312f45f1 100644 --- a/internal/fs/const_windows.go +++ b/internal/fs/const_windows.go @@ -11,3 +11,9 @@ const O_NOFOLLOW int = 0x40000000 // O_DIRECTORY is a noop on Windows. const O_DIRECTORY int = 0 + +// sanitizeFlags cleans up flags that conflict with actual OS API flags +// Must only be used right before passing the flags to the go stdlib. +func sanitizeFlags(flags int) int { + return flags &^ O_NOFOLLOW +} diff --git a/internal/fs/file.go b/internal/fs/file.go index 57f1a996a..21ba4244a 100644 --- a/internal/fs/file.go +++ b/internal/fs/file.go @@ -3,7 +3,6 @@ package fs import ( "fmt" "os" - "runtime" ) // MkdirAll creates a directory named path, along with any necessary parents, @@ -48,10 +47,7 @@ func Lstat(name string) (os.FileInfo, error) { // methods on the returned File can be used for I/O. // If there is an error, it will be of type *PathError. func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) { - if runtime.GOOS == "windows" { - flag &^= O_NOFOLLOW - } - return os.OpenFile(fixpath(name), flag, perm) + return os.OpenFile(fixpath(name), sanitizeFlags(flag), perm) } // IsAccessDenied checks if the error is due to permission error. diff --git a/internal/fs/fs_local.go b/internal/fs/fs_local.go index 5b2f192fd..d5a9001a2 100644 --- a/internal/fs/fs_local.go +++ b/internal/fs/fs_local.go @@ -106,7 +106,7 @@ func newLocalFile(name string, flag int, metadataOnly bool) (*localFile, error) var f *os.File if !metadataOnly { var err error - f, err = os.OpenFile(fixpath(name), flag, 0) + f, err = os.OpenFile(fixpath(name), sanitizeFlags(flag), 0) if err != nil { return nil, err }