diff options
| author | Jonathan Amsterdam <jba@google.com> | 2020-08-21 19:31:08 -0400 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2020-08-25 18:52:53 +0000 |
| commit | d25b304adb7670d05913a46af0cddcfca4e5cc02 (patch) | |
| tree | 5492903ac5630ead161bdee035f134ad5a8a1f9e /internal/postgres/insert_module.go | |
| parent | 41dc6b274dec8f67939c151c82b50044b08a9fb5 (diff) | |
| download | go-x-pkgsite-d25b304adb7670d05913a46af0cddcfca4e5cc02.tar.xz | |
internal,internal/postgres: remove non-redist data on read
The postgres package removes non-redistributable data during
insertion. Also remove it when reading, unless bypassLicenseCheck is
true.
Handling this in the DataSource layer simplifies frontend code, which
can avoid redistributability checks and knowing about the bypass flag
except when it constructs its DataSource.
As part of this work, move the removal of non-redistributable data to
the internal package, so it can eventually be used by the proxy data
source.
For golang/go#39602
Change-Id: Ia1362ead917b42f844b4c4d25ade74cdcb03d4dc
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/250017
Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/postgres/insert_module.go')
| -rw-r--r-- | internal/postgres/insert_module.go | 35 |
1 files changed, 2 insertions, 33 deletions
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go index 474b6ed5..2af86f90 100644 --- a/internal/postgres/insert_module.go +++ b/internal/postgres/insert_module.go @@ -17,7 +17,6 @@ import ( "strings" "unicode/utf8" - "github.com/google/safehtml" "github.com/lib/pq" "go.opencensus.io/trace" "golang.org/x/mod/module" @@ -25,7 +24,6 @@ import ( "golang.org/x/pkgsite/internal" "golang.org/x/pkgsite/internal/database" "golang.org/x/pkgsite/internal/derrors" - "golang.org/x/pkgsite/internal/licenses" "golang.org/x/pkgsite/internal/log" "golang.org/x/pkgsite/internal/stdlib" "golang.org/x/pkgsite/internal/version" @@ -64,8 +62,8 @@ func (db *DB) InsertModule(ctx context.Context, m *internal.Module) (err error) return err } if !db.bypassLicenseCheck { - // If we are bypassing license checking, remove data for non-redistributable modules. - removeNonDistributableData(m) + // If we are not bypassing license checking, remove data for non-redistributable modules. + m.RemoveNonRedistributableData() } return db.saveModule(ctx, m) } @@ -692,35 +690,6 @@ func (db *DB) comparePaths(ctx context.Context, m *internal.Module) (err error) return nil } -// removeNonDistributableData removes information from the module -// if it is not redistributable. -func removeNonDistributableData(m *internal.Module) { - for _, p := range m.LegacyPackages { - if !p.IsRedistributable { - // Prune derived information that can't be stored. - p.Synopsis = "" - p.DocumentationHTML = safehtml.HTML{} - } - } - if !m.IsRedistributable { - m.LegacyReadmeFilePath = "" - m.LegacyReadmeContents = "" - } - for _, d := range m.Directories { - if !d.IsRedistributable { - d.Readme = nil - if d.Package != nil { - d.Package.Documentation = nil - } - } - } - for _, l := range m.Licenses { - if !licenses.Redistributable(l.Types) { - l.Contents = nil - } - } -} - // DeleteModule deletes a Version from the database. func (db *DB) DeleteModule(ctx context.Context, modulePath, version string) (err error) { defer derrors.Wrap(&err, "DeleteModule(ctx, db, %q, %q)", modulePath, version) |
