diff options
| author | Jonathan Amsterdam <jba@google.com> | 2022-01-05 12:59:20 -0500 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2022-01-05 18:41:31 +0000 |
| commit | 9e605dc9e8da545178f0a093bf3dd6754d52e3db (patch) | |
| tree | c8c891aa8933545c6fdbea41592e573792ff968b /internal/fetchdatasource/fetchdatasource.go | |
| parent | 9c33d633fc3a5480f9d10fbb5540cae862fc5b46 (diff) | |
| download | go-x-pkgsite-9e605dc9e8da545178f0a093bf3dd6754d52e3db.tar.xz | |
internal/fetchdatasource: add directory information
When fetching a module, populate information about unit
subdirectories.
Normally (when using a DB) we don't need to do this because a DB query
synthesizes it from the units table, but FetchDataSource returns
information for immediate consumption so it has to do it on its own.
One difference between this and the DB path: this won't have
submodules, since FetchDataSource processes one module at a time.
Fixes golang/go#49847
Change-Id: I7a215e03dd9cebe31a14c3c118c42978f3f7c8a3
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/375714
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/fetchdatasource/fetchdatasource.go')
| -rw-r--r-- | internal/fetchdatasource/fetchdatasource.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/internal/fetchdatasource/fetchdatasource.go b/internal/fetchdatasource/fetchdatasource.go index 4af79cc0..87a69fb1 100644 --- a/internal/fetchdatasource/fetchdatasource.go +++ b/internal/fetchdatasource/fetchdatasource.go @@ -108,6 +108,13 @@ func (ds *FetchDataSource) getModule(ctx context.Context, modulePath, vers strin lmv.PopulateModuleInfo(&m.ModuleInfo) } } + // Populate unit subdirectories. When we use a database, this only happens when we read + // a unit from the DB. + if m != nil { + for _, u := range m.Units { + ds.populateUnitSubdirectories(u, m) + } + } // Cache both successes and failures, but not cancellations. if !errors.Is(err, context.Canceled) { @@ -150,6 +157,25 @@ func (ds *FetchDataSource) fetch(ctx context.Context, modulePath, version string return nil, fmt.Errorf("%s@%s: %w", modulePath, version, derrors.NotFound) } +func (ds *FetchDataSource) populateUnitSubdirectories(u *internal.Unit, m *internal.Module) { + p := u.Path + "/" + for _, u2 := range m.Units { + if strings.HasPrefix(u2.Path, p) { + var syn string + if len(u2.Documentation) > 0 { + syn = u2.Documentation[0].Synopsis + } + u.Subdirectories = append(u.Subdirectories, &internal.PackageMeta{ + Path: u2.Path, + Name: u2.Name, + Synopsis: syn, + IsRedistributable: u2.IsRedistributable, + Licenses: u2.Licenses, + }) + } + } +} + // findModule finds the module with longest module path containing the given // package path. It returns an error if no module is found. func (ds *FetchDataSource) findModule(ctx context.Context, pkgPath, modulePath, version string) (_ *internal.Module, err error) { |
