cmd/go/internal/modload: delete unused files

There is currently no place to call this function: hasWritePerm, these files are no longer needed.

Change-Id: Ifabc7432fd411152696b6b0241d60dbc03e8c959
GitHub-Last-Rev: b82d773317
GitHub-Pull-Request: golang/go#68510
Reviewed-on: https://go-review.googlesource.com/c/go/+/599355
Reviewed-by: Michael Matloob <matloob@golang.org>
Auto-Submit: Michael Matloob <matloob@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@google.com>
This commit is contained in:
WuGuangyao
2024-07-18 14:26:06 +00:00
committed by Gopher Robot
parent 34ff24cb4b
commit 105b1e2757
3 changed files with 0 additions and 81 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}