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

fix: patch support for dir named workspace #1606

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}