Merge pull request #21798 from MichaelEischer/fix-windows-test-flake

windows: try to fix flaky tests
This commit is contained in:
Michael Eischer
2026-05-12 18:53:31 +02:00
committed by GitHub
+5 -3
View File
@@ -6,7 +6,6 @@ import (
"path/filepath"
"strconv"
"strings"
"time"
"github.com/restic/restic/internal/data"
"golang.org/x/sys/windows"
@@ -63,9 +62,8 @@ func TempFile(dir, prefix string) (f *os.File, err error) {
share := uint32(0) // prevent other processes from accessing the file
flags := uint32(windows.FILE_ATTRIBUTE_TEMPORARY | windows.FILE_FLAG_DELETE_ON_CLOSE)
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < 10000; i++ {
randSuffix := strconv.Itoa(int(1e9 + rnd.Intn(1e9)%1e9))[1:]
randSuffix := strconv.Itoa(int(1e9 + rand.Intn(1e9)%1e9))[1:]
path := filepath.Join(dir, prefix+randSuffix)
ptr, err := windows.UTF16PtrFromString(path)
@@ -76,6 +74,10 @@ func TempFile(dir, prefix string) (f *os.File, err error) {
if os.IsExist(err) {
continue
}
// Access denied error can occur if the tmp files conflict with each other.
if isAccessDeniedError(err) {
continue
}
return os.NewFile(uintptr(h), path), err
}