diff --git a/src/cmd/go/internal/modload/stat_openfile.go b/src/cmd/go/internal/modload/stat_openfile.go deleted file mode 100644 index 5773073d903..00000000000 --- a/src/cmd/go/internal/modload/stat_openfile.go +++ /dev/null @@ -1,28 +0,0 @@ -// 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. - -//go:build (js && wasm) || plan9 - -// On plan9, per http://9p.io/magic/man2html/2/access: “Since file permissions -// are checked by the server and group information is not known to the client, -// access must open the file to check permissions.” -// -// js,wasm is similar, in that it does not define syscall.Access. - -package modload - -import ( - "io/fs" - "os" -) - -// hasWritePerm reports whether the current user has permission to write to the -// file with the given info. -func hasWritePerm(path string, _ fs.FileInfo) bool { - if f, err := os.OpenFile(path, os.O_WRONLY, 0); err == nil { - f.Close() - return true - } - return false -} diff --git a/src/cmd/go/internal/modload/stat_unix.go b/src/cmd/go/internal/modload/stat_unix.go deleted file mode 100644 index a0d5f4d2476..00000000000 --- a/src/cmd/go/internal/modload/stat_unix.go +++ /dev/null @@ -1,32 +0,0 @@ -// 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. - -//go:build unix - -package modload - -import ( - "io/fs" - "os" - "syscall" -) - -// hasWritePerm reports whether the current user has permission to write to the -// file with the given info. -// -// Although the root user on most Unix systems can write to files even without -// permission, hasWritePerm reports false if no appropriate permission bit is -// set even if the current user is root. -func hasWritePerm(path string, fi fs.FileInfo) bool { - if os.Getuid() == 0 { - // The root user can access any file, but we still want to default to - // read-only mode if the go.mod file is marked as globally non-writable. - // (If the user really intends not to be in readonly mode, they can - // pass -mod=mod explicitly.) - return fi.Mode()&0222 != 0 - } - - const W_OK = 0x2 - return syscall.Access(path, W_OK) == nil -} diff --git a/src/cmd/go/internal/modload/stat_windows.go b/src/cmd/go/internal/modload/stat_windows.go deleted file mode 100644 index f29a99165e5..00000000000 --- a/src/cmd/go/internal/modload/stat_windows.go +++ /dev/null @@ -1,21 +0,0 @@ -// 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. - -//go:build windows - -package modload - -import "io/fs" - -// hasWritePerm reports whether the current user has permission to write to the -// file with the given info. -func hasWritePerm(_ string, fi fs.FileInfo) bool { - // Windows has a read-only attribute independent of ACLs, so use that to - // determine whether the file is intended to be overwritten. - // - // Per https://golang.org/pkg/os/#Chmod: - // “On Windows, only the 0200 bit (owner writable) of mode is used; it - // controls whether the file's read-only attribute is set or cleared.” - return fi.Mode()&0200 != 0 -}