CL 172418 added code to check for "Access is denied" error.
But "Access is denied" error will be spelled differently on
non-English version of Windows.
Check if error is ERROR_ACCESS_DENIED instead.
Updates #31247
Change-Id: I7b1633013d563f7c06c1f12a9be75122106834f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/174123
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
--- /dev/null
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build !windows
+
+package renameio
+
+// isAccessDeniedError always returns false on non-windows.
+func isAccessDeniedError(err error) bool {
+ return false
+}
--- /dev/null
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package renameio
+
+import (
+ "os"
+ "syscall"
+)
+
+// isAccessDeniedError returns true if err was caused by ERROR_ACCESS_DENIED.
+func isAccessDeniedError(err error) bool {
+ linkerr, ok := err.(*os.LinkError)
+ if !ok {
+ return false
+ }
+ errno, ok := linkerr.Err.(syscall.Errno)
+ if !ok {
+ return false
+ }
+ return errno == syscall.ERROR_ACCESS_DENIED
+}
"io/ioutil"
"os"
"path/filepath"
- "runtime"
- "strings"
"time"
)
var start time.Time
for {
err := os.Rename(f.Name(), filename)
- if err == nil || runtime.GOOS != "windows" || !strings.HasSuffix(err.Error(), "Access is denied.") {
+ if err == nil || !isAccessDeniedError(err) {
return err
}