diff --git a/internal/fs/file_windows.go b/internal/fs/file_windows.go index 2aa050d2c..30cb75da5 100644 --- a/internal/fs/file_windows.go +++ b/internal/fs/file_windows.go @@ -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 }