Skip to content

Commit f17f523

Browse files
mateusz834gopherbot
authored andcommitted
go/packages: remove filepath.Abs call in getPkgPath
getPkgPath is only called in one place and it is already guarded with filepath.IsAbs, so we don't have to call filepath.Abs here. go/packages should not call filepath.Abs (as the working directory is configurable cfg.Dir), here we can avoid that. Change-Id: I50320387dd56bbe8809d36ceccf92f8b7d5d30ff Reviewed-on: https://go-review.googlesource.com/c/tools/+/680818 Reviewed-by: Alan Donovan <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Commit-Queue: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent f0ace13 commit f17f523

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

go/packages/golist.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,8 @@ func (state *golistState) getGoVersion() (int, error) {
712712
// getPkgPath finds the package path of a directory if it's relative to a root
713713
// directory.
714714
func (state *golistState) getPkgPath(dir string) (string, bool, error) {
715-
absDir, err := filepath.Abs(dir)
716-
if err != nil {
717-
return "", false, err
715+
if !filepath.IsAbs(dir) {
716+
panic("non-absolute dir passed to getPkgPath")
718717
}
719718
roots, err := state.determineRootDirs()
720719
if err != nil {
@@ -724,7 +723,7 @@ func (state *golistState) getPkgPath(dir string) (string, bool, error) {
724723
for rdir, rpath := range roots {
725724
// Make sure that the directory is in the module,
726725
// to avoid creating a path relative to another module.
727-
if !strings.HasPrefix(absDir, rdir) {
726+
if !strings.HasPrefix(dir, rdir) {
728727
continue
729728
}
730729
// TODO(matloob): This doesn't properly handle symlinks.

0 commit comments

Comments
 (0)