-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: default to mod=readonly when the go.mod file is read-only
Updates #30185 Updates #33326 Updates #34822 Change-Id: Ie13651585898d1bbbf4f779b97ee50b6c7e7ad50 Reviewed-on: https://go-review.googlesource.com/c/go/+/204521 Run-TryBot: Bryan C. Mills <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
- Loading branch information
Bryan C. Mills
committed
Nov 1, 2019
1 parent
8d45e61
commit 2c8529c
Showing
9 changed files
with
143 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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 aix 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.” | ||
// | ||
// aix and js,wasm are similar, in that they do not define syscall.Access. | ||
|
||
package modload | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// hasWritePerm reports whether the current user has permission to write to the | ||
// file with the given info. | ||
func hasWritePerm(path string, _ os.FileInfo) bool { | ||
if f, err := os.OpenFile(path, os.O_WRONLY, 0); err == nil { | ||
f.Close() | ||
return true | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// 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 darwin dragonfly freebsd linux netbsd openbsd solaris | ||
|
||
package modload | ||
|
||
import ( | ||
"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 os.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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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 modload | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// hasWritePerm reports whether the current user has permission to write to the | ||
// file with the given info. | ||
func hasWritePerm(_ string, fi os.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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,6 @@ go list -f {{.Dir}} -tags tools all | |
stdout '^'$WORK'[/\\]auto$' | ||
stdout '^'$GOPATH'[/\\]pkg[/\\]mod[/\\]example.com[/\\][email protected]$' | ||
stdout '^'$WORK'[/\\]auto[/\\]replacement-version$' | ||
stderr '^go: not defaulting to -mod=vendor because go.mod .go. version is 1.13$' | ||
|
||
go list -m -f '{{.Dir}}' all | ||
stdout '^'$WORK'[/\\]auto$' | ||
|
@@ -146,7 +145,6 @@ go list -mod=vendor -f {{.Dir}} -tags tools all | |
stdout '^'$WORK'[/\\]auto$' | ||
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$' | ||
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$' | ||
! stderr 'not defaulting to -mod=vendor' | ||
|
||
# ...but a version mismatch for an explicit dependency should be noticed. | ||
cp $WORK/modules-bad-1.13.txt vendor/modules.txt | ||
|