diff --git a/cmd/gazelle/fix-update.go b/cmd/gazelle/fix-update.go index d99141fcb..4baa96942 100644 --- a/cmd/gazelle/fix-update.go +++ b/cmd/gazelle/fix-update.go @@ -18,6 +18,7 @@ package main import ( "bytes" "context" + "errors" "flag" "fmt" "io/ioutil" @@ -26,6 +27,7 @@ import ( "path/filepath" "sort" "strings" + "syscall" "github.com/bazelbuild/bazel-gazelle/config" gzflag "github.com/bazelbuild/bazel-gazelle/flag" @@ -142,7 +144,7 @@ func (ucr *updateConfigurer) CheckFlags(fs *flag.FlagSet, c *config.Config) erro ucr.repoConfigPath = wspace.FindWORKSPACEFile(c.RepoRoot) } repoConfigFile, err := rule.LoadWorkspaceFile(ucr.repoConfigPath, "") - if err != nil && !os.IsNotExist(err) { + if err != nil && !os.IsNotExist(err) && !isDirErr(err) { return err } else if err == nil { c.Repos, _, err = repo.ListRepositories(repoConfigFile) @@ -741,3 +743,14 @@ func appendOrMergeKindMapping(mappedLoads []rule.LoadInfo, mappedKind config.Map Symbols: []string{mappedKind.KindName}, }) } + +func isDirErr(err error) bool { + if err == nil { + return false + } + var pe *os.PathError + if errors.As(err, &pe) { + return pe.Err == syscall.EISDIR + } + return false +}