Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go mod creates files with incorrect read-only permissions #35615

Closed
0intro opened this issue Nov 15, 2019 · 3 comments
Closed

cmd/go: go mod creates files with incorrect read-only permissions #35615

0intro opened this issue Nov 15, 2019 · 3 comments

Comments

@0intro
Copy link
Member

0intro commented Nov 15, 2019

What version of Go are you using (go version)?

$ go version
go version devel +498eaee461 Fri Nov 15 02:31:58 2019 +0000 linux/amd64

Does this issue reproduce with the latest release?

No.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/djc/.cache/go-build"
GOENV="/home/djc/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/djc/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build726010483=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ mkdir pkg
$ cd pkg
$ go mod init example.com/m
go: creating new go.mod: module example.com/m
$ echo -e 'package pkg\nimport "golang.org/x/image/bmp"' >pkg.go
$ go get ...
go: downloading golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8
go: finding versions for golang.org/x/image/bmp
go: found golang.org/x/image/bmp in golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8
go: downloading golang.org/x/text v0.3.0
go: downloading golang.org/x/tools v0.0.0-20191114222411-4191b8cbba09
go: found golang.org/x/tools/go/buildutil in golang.org/x/tools v0.0.0-20191114222411-4191b8cbba09
go: downloading golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
go: downloading golang.org/x/net v0.0.0-20190620200207-3b0461eec859
go: downloading golang.org/x/sync v0.0.0-20190423024810-112230192c58
go: downloading golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
go: downloading golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
go: golang.org/x/sync upgrade => v0.0.0-20190911185100-cd5d95a43a6e
go: golang.org/x/text upgrade => v0.3.2
go: golang.org/x/sys upgrade => v0.0.0-20191113165036-4c7a9d0fe056
go: golang.org/x/net upgrade => v0.0.0-20191112182307-2180aed22343
go: golang.org/x/crypto upgrade => v0.0.0-20191112222119-e1110fd1c708
go: golang.org/x/xerrors upgrade => v0.0.0-20191011141410-1b5146add898
go: downloading golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708
go: downloading golang.org/x/net v0.0.0-20191112182307-2180aed22343
go: downloading golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
go: downloading golang.org/x/sys v0.0.0-20191113165036-4c7a9d0fe056
go: downloading golang.org/x/text v0.3.2
go: downloading golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898
# example.com/m
./pkg.go:2:8: imported and not used: "golang.org/x/image/bmp"

The files created by go mod have incorrect 444 (read-only) permissions:

$ ls -l $GOPATH/pkg/mod/golang.org/x/image*
total 96
-r--r--r--. 1 djc djc  173 Nov 15 10:49 AUTHORS
dr-xr-xr-x. 2 djc djc 4096 Nov 15 10:49 bmp
dr-xr-xr-x. 3 djc djc 4096 Nov 15 10:49 ccitt
dr-xr-xr-x. 3 djc djc 4096 Nov 15 10:49 cmd
-r--r--r--. 1 djc djc   21 Nov 15 10:49 codereview.cfg
dr-xr-xr-x. 2 djc djc 4096 Nov 15 10:49 colornames
-r--r--r--. 1 djc djc  913 Nov 15 10:49 CONTRIBUTING.md
-r--r--r--. 1 djc djc  170 Nov 15 10:49 CONTRIBUTORS
dr-xr-xr-x. 2 djc djc 4096 Nov 15 10:49 draw
dr-xr-xr-x. 3 djc djc 4096 Nov 15 10:49 example
dr-xr-xr-x. 9 djc djc 4096 Nov 15 10:49 font
-r--r--r--. 1 djc djc   69 Nov 15 10:49 go.mod
-r--r--r--. 1 djc djc  153 Nov 15 10:49 go.sum
-r--r--r--. 1 djc djc 1479 Nov 15 10:49 LICENSE
dr-xr-xr-x. 5 djc djc 4096 Nov 15 10:49 math
-r--r--r--. 1 djc djc 1303 Nov 15 10:49 PATENTS
-r--r--r--. 1 djc djc  601 Nov 15 10:49 README.md
dr-xr-xr-x. 2 djc djc 4096 Nov 15 10:49 riff
dr-xr-xr-x. 2 djc djc 4096 Nov 15 10:49 testdata
dr-xr-xr-x. 3 djc djc 4096 Nov 15 10:49 tiff
dr-xr-xr-x. 2 djc djc 4096 Nov 15 10:49 vector
dr-xr-xr-x. 2 djc djc 4096 Nov 15 10:49 vp8
dr-xr-xr-x. 2 djc djc 4096 Nov 15 10:49 vp8l
dr-xr-xr-x. 2 djc djc 4096 Nov 15 10:49 webp

Consequently, these files cannot be deleted:

$ rm -rf $GOPATH/pkg/mod
rm: cannot remove '/home/djc/go/pkg/mod/golang.org/x/crypto@v0.0.0-20190308221718-c2843e01d9a2/internal/subtle/aliasing.go': Permission denied
rm: cannot remove '/home/djc/go/pkg/mod/golang.org/x/crypto@v0.0.0-20190308221718-c2843e01d9a2/internal/subtle/aliasing_test.go': Permission denied
rm: cannot remove '/home/djc/go/pkg/mod/golang.org/x/crypto@v0.0.0-20190308221718-c2843e01d9a2/internal/subtle/aliasing_appengine.go': Permission denied
rm: cannot remove '/home/djc/go/pkg/mod/golang.org/x/crypto@v0.0.0-20190308221718-c2843e01d9a2/internal/chacha20/chacha_s390x.s': Permission denied
[...]

With correct permissions, the files can be deleted successfully:

$ find $GOPATH/pkg/mod -exec chmod u+w {} \;
$ rm -rf $GOPATH/pkg/mod
$

What did you expect to see?

The files created by go mod should have correct read-write permissions, so they can be deleted by their owner.

What did you see instead?

The files created by go mod have incorrect read-only permissions, so they can't be deleted.

This may be releated to issue #34634.

@0intro 0intro added this to the Go1.14 milestone Nov 15, 2019
@mvdan
Copy link
Member

mvdan commented Nov 15, 2019

Have you seen earlier issues like #27161 and #31481? This seems to be on purpose.

You can use go clean -modcache to get rid of all those files without chmod shenanigans.

@0intro
Copy link
Member Author

0intro commented Nov 15, 2019

Thanks. That's interesting. I'm experiencing side effects related with this behaviour. I'll investigate.

@0intro
Copy link
Member Author

0intro commented Nov 15, 2019

I'm closing this issue since it seems to be the expected behaviour.

@0intro 0intro closed this as completed Nov 15, 2019
@golang golang locked and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants