x/tools/cmd/goimports: permission denied causes imports to stop
#16,890 opened on Aug 26, 2016
Repository metrics
- Stars
- (133,883 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
Please answer these questions before submitting your issue. Thanks!
- What version of Go are you using (
go version)?
go version go1.7 darwin/amd64
- What operating system and processor architecture are you using (
go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/jeffwilliams/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/jc/ctl0fvhs34v21m_hg1z3w0zh0000gp/T/go-build379181819=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
- What did you do? If possible, provide a recipe for reproducing the error. A complete runnable program is good. A link on play.golang.org is best.
One unreadable dir in GOPATH will cause the walk to fail and ignore all directories after that point, with a confusing message like:
2016/08/26 15:39:24 goimports: scanning directory /Users/jeffwilliams/go/src: permission denied
In this case, it was a test dir with permissions 0000:
/Users/jeffwilliams/go/src/github.com/wherethebitsroam/cloudcp/test/fred/dave
Admittedly, moving this test content into testdata where it should have been fixed the problem. But this is not very obvious given the error.
The relevant code was golang.org/x/tools/imports/fastwalk_unix.go:
fd, err := syscall.Open(dirName, 0, 0)
- What did you expect to see?
goimports to skip the directory with permission denied. Or at least give an error with the directory which was the problem.
- What did you see instead?
goimports failed to insert the imports for known packages in the file being processed.