windows: fix hang while reading from directory

This commit is contained in:
Michael Eischer
2026-05-10 01:07:34 +02:00
parent a1c870c675
commit a241652787
5 changed files with 16 additions and 6 deletions
+2
View File
@@ -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
+6
View File
@@ -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
}
+6
View File
@@ -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
}
+1 -5
View File
@@ -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.
+1 -1
View File
@@ -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
}