Commit e85d6195 authored by Alex Brainman's avatar Alex Brainman

cmd/go/internal/renameio: use ERROR_ACCESS_DENIED to check for errors

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/+/174123Reviewed-by: default avatarEmmanuel Odeke <emm.odeke@gmail.com>
parent 4fdeb73f
// 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
}
// 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
}
...@@ -11,8 +11,6 @@ import ( ...@@ -11,8 +11,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"strings"
"time" "time"
) )
...@@ -66,7 +64,7 @@ func WriteToFile(filename string, data io.Reader) (err error) { ...@@ -66,7 +64,7 @@ func WriteToFile(filename string, data io.Reader) (err error) {
var start time.Time var start time.Time
for { for {
err := os.Rename(f.Name(), filename) 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 return err
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment