Skip to content

Commit

Permalink
fix: patch support for dir named workspace (bazel-contrib#1606)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaellzc authored and jeromep-stripe committed Mar 22, 2024
1 parent dd65d82 commit f59921a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions cmd/gazelle/fix-update.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main
import (
"bytes"
"context"
"errors"
"flag"
"fmt"
"io/ioutil"
Expand All @@ -26,6 +27,7 @@ import (
"path/filepath"
"sort"
"strings"
"syscall"

"github.com/bazelbuild/bazel-gazelle/config"
gzflag "github.com/bazelbuild/bazel-gazelle/flag"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -185,7 +187,7 @@ func (ucr *updateConfigurer) CheckFlags(fs *flag.FlagSet, c *config.Config) erro
workspace = repoConfigFile
} else {
workspace, err = rule.LoadWorkspaceFile(workspacePath, "")
if err != nil && !os.IsNotExist(err) {
if err != nil && !os.IsNotExist(err) && !isDirErr(err) {
return err
}
}
Expand Down Expand Up @@ -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
}

0 comments on commit f59921a

Please sign in to comment.