Skip to content

Commit a769f88

Browse files
committed
client: query index in GetByModule for localSource
This keeps logic in sync with httpSource and supports local development where top-level module names are invalid, aka, "moduleX". Otherwise, EscapeModulePath needs to be changed. Fixes golang/go#56179 Change-Id: Ic91c89155cb985ddcd56e812ce48497a4c87812c Reviewed-on: https://go-review.googlesource.com/c/vuln/+/442975 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]> Run-TryBot: Zvonimir Pavlinovic <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent be6bc7b commit a769f88

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

client/client.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,20 @@ type localSource struct {
8989

9090
func (*localSource) unexported() {}
9191

92-
func (ls *localSource) GetByModule(_ context.Context, modulePath string) (_ []*osv.Entry, err error) {
92+
func (ls *localSource) GetByModule(ctx context.Context, modulePath string) (_ []*osv.Entry, err error) {
9393
defer derrors.Wrap(&err, "localSource.GetByModule(%q)", modulePath)
94+
95+
index, err := ls.Index(ctx)
96+
if err != nil {
97+
return nil, err
98+
}
99+
// Query index first to be consistent with the way httpSource.GetByModule works.
100+
// Prevents opening and stating files on disk that don't need to be touched. Also
101+
// solves #56179.
102+
if _, present := index[modulePath]; !present {
103+
return nil, nil
104+
}
105+
94106
epath, err := EscapeModulePath(modulePath)
95107
if err != nil {
96108
return nil, err
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"stdlib":"2022-09-20T15:16:04Z","github.com/shiyanhui/dht":"2022-09-20T15:16:04Z","github.com/tidwall/gjson":"2022-09-20T15:16:04Z","golang.org/x/crypto":"2022-09-20T15:16:04Z","golang.org/x/net":"2022-09-20T15:16:04Z","golang.org/x/text":"2022-09-20T15:16:04Z"}

0 commit comments

Comments
 (0)