Skip to content

Commit

Permalink
fix: PkgSourceDir 现在可正确区分拥有相同前缀的不同包
Browse files Browse the repository at this point in the history
比如 github.com/issue9/web 与 github.com/issue9/webuse
  • Loading branch information
caixw committed May 10, 2024
1 parent c21aa9d commit 508dd92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func PkgSourceDir(pkgPath, modDir string, replace bool) (dir string, err error)
continue
}
suffix := strings.TrimPrefix(pkgPath, pkg.Mod.Path)
// github.com/issue9/web 与 github.com/issue9/webuse 也匹配,但不是同一个包
// 只有 github.com/issue9/web 与 github.com/issue9/web/v4 这种才行
if suffix != "" && suffix[0] != '/' {
continue
}

if !replace {
return filepath.Join(pkgSource, pkg.Mod.Path+"@"+pkg.Mod.Version+suffix), nil
Expand Down
3 changes: 3 additions & 0 deletions mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func TestPkgSourceDir(t *testing.T) {
a.NotError(err).FileExists(dir).
True(strings.HasSuffix(filepath.ToSlash(dir), "assert/[email protected]/rest"))

dir, err = PkgSourceDir("github.com/issue9/assertxx", "./", false)
a.ErrorIs(err, fs.ErrNotExist)

// replace

dir, err = PkgSourceDir("github.com/issue9/web/v2", "./testdata/go.mod", true)
Expand Down

0 comments on commit 508dd92

Please sign in to comment.