Skip to content

x/tools/cmd/goimports: permission denied causes imports to stop #16890

@jeffw-wherethebitsroam

Description

@jeffw-wherethebitsroam

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
go version go1.7 darwin/amd64
  1. 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"
  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)
  1. 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.

  1. What did you see instead?

goimports failed to insert the imports for known packages in the file being processed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolsThis label describes issues relating to any tools in the x/tools repository.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions