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: incorrect permissions (0400, read-only) set by `go mod vendor`? #27455

Closed
bmeh opened this issue Sep 2, 2018 · 11 comments

Comments

Projects
None yet
5 participants
@bmeh
Copy link

commented Sep 2, 2018

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

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/bmeh/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/bmeh/go"
GOPROXY=""
GORACE=""
GOROOT="/home/bmeh/.local/pkg/go-1.11"
GOTMPDIR=""
GOTOOLDIR="/home/bmeh/.local/pkg/go-1.11/pkg/tool/linux_amd64"
GCCGO="gccgo"
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-build187236244=/tmp/go-build -gno-record-gcc-switches"

What did you do?

[...]
$ go mod init
$ go mod vendor
$ rm -rf $GOPATH/pkg/mod

What did you expect to see?

I expected to have read and write permissions (i.e. have at the very least 0600, but apparently ALL pkg/mod/*/*/*@*/*.go files are read-only (0400/-r--------). Is this a bug or feature? It's definitely an annoyance.

What did you see instead?

rm: cannot remove 'pkg/mod/*/*/*@*/*.go': Permission denied
[...]
@crvv

This comment has been minimized.

Copy link
Contributor

commented Sep 3, 2018

For a repo github.com/user/package

The directory mod/github.com/user/package@v0.0.0... has permission 0555.
Files inside it can't be deleted.

The permission of directories in mod/github.com/user/package@v0.0.0... is 0755,
Files in mod/github.com/user/package@v0.0.0.../subdir can be deleted.

All files in mod/github.com/user/package@v0.0.0...(including subdirectories) has permission 0400.

This looks like a feature, but currently it is inconsistent.

@bmeh

This comment has been minimized.

Copy link
Author

commented Sep 3, 2018

In my case: https://slexy.org/view/s2deKExjfk

I don't see why it should be the case, I have to either recursively change the permissions,
or use sudo rm -rf $GOPATH/pkg/mod/.

@crvv

This comment has been minimized.

Copy link
Contributor

commented Sep 3, 2018

I tested with an outdated go.
The inconsistence has been fixed. All files can't be deleted now.

@mark-rushakoff

This comment has been minimized.

Copy link
Contributor

commented Sep 3, 2018

@rsc discussed this on the mailing list on July 13:

I can't do rm -fr $GOPATH/src/mod because the directory with the @ (in my case golang.org/x/crypto@) is not writable for the user.

Yes, this is really annoying: when I made the directories unwritable I thought that rm -rf would still work on them, and I'm disappointed that it doesn't. Even so, I do think it's important to keep them unwritable to prevent accidental modification. I intend to add 'go clean -modcache' or something like that to blow away that tree for you (chmod + rm), so even though rm -rf fails, there will be an easy command.

go clean -modcache does appear to be implemented in the go1.11 release.

@myitcv

This comment has been minimized.

Copy link
Member

commented Sep 3, 2018

This is, as @mark-rushakoff pointed out, working as intended. The integrity of pkg/mod/** is important. Hence it is not writable.

@myitcv myitcv closed this Sep 3, 2018

@myitcv myitcv added the modules label Sep 3, 2018

@myitcv myitcv changed the title Incorrect permissions (0400, read-only) set by `go mod vendor` cmd/go: incorrect permissions (0400, read-only) set by `go mod vendor`? Sep 3, 2018

@bmeh

This comment has been minimized.

Copy link
Author

commented Sep 3, 2018

Is it a reasonable way to ensure data integrity? What is the reasoning behind this? Human error, as in accidental typing of rm -rf $GOPATH/pkg/mod?

@myitcv

This comment has been minimized.

Copy link
Member

commented Sep 3, 2018

You make a fair point which is why Russ commented:

Yes, this is really annoying: when I made the directories unwritable I thought that rm -rf would still work on them, and I'm disappointed that it doesn't.

This minor pain is alleviated by go clean -modcache followed by the rm -rf

@bmeh

This comment has been minimized.

Copy link
Author

commented Sep 3, 2018

go clean -modcache nukes $GOPATH/pkg/mod entirely though, so there's nothing left to rm -rf. :D

$ ls $GOPATH/pkg/mod
cache  github.com  golang.org
$ go clean -modcache
$ ls $GOPATH/pkg/mod
ls: cannot access '/home/bmeh/go/pkg/mod': No such file or directory
@myitcv

This comment has been minimized.

Copy link
Member

commented Sep 3, 2018

Ok, so go clean -modcache covers your case entirely then?

@FiloSottile

This comment has been minimized.

Copy link
Member

commented Sep 5, 2018

Duplicate of #27161

@FiloSottile FiloSottile marked this as a duplicate of #27161 Sep 5, 2018

@FiloSottile

This comment has been minimized.

Copy link
Member

commented Sep 23, 2018

@benixlinux This is not the appropriate forum for your comment. If you'd like to make a Code of Conduct report, you can follow the process at https://golang.org/conduct.

@golang golang deleted a comment Sep 23, 2018

jefferyto added a commit to jefferyto/packages that referenced this issue Dec 11, 2018

golang: fix package clean / autoremove, add output whitespace
go 1.11 added modules, which are cached locally. The go developers have
decided to make this cache read-only (golang/go#27455), which causes
problems with package clean / autoremove (openwrt#7635).

This adds a call to clear this cache right after building, as currently
there is no easy way to hook into autoremove (it may be possible to hook
into package clean).

This also adds whitespace (blank lines) to certain places in make
output, to aid debugging.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>

thiagoricciardi added a commit to thiagoricciardi/packages that referenced this issue Apr 3, 2019

golang: fix package clean / autoremove, add output whitespace
go 1.11 added modules, which are cached locally. The go developers have
decided to make this cache read-only (golang/go#27455), which causes
problems with package clean / autoremove (openwrt#7635).

This adds a call to clear this cache right after building, as currently
there is no easy way to hook into autoremove (it may be possible to hook
into package clean).

This also adds whitespace (blank lines) to certain places in make
output, to aid debugging.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.