diff options
| author | Jonathan Amsterdam <jba@google.com> | 2019-12-19 07:44:36 -0500 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2020-03-27 16:46:50 -0400 |
| commit | a72c2ab9ef763fea88a865dfb39feb6df9829580 (patch) | |
| tree | 33af0b72592d3b3cbab1b41df79ac020e9133a0f /internal/stdlib/stdlib.go | |
| parent | 8466218d123f86aed4feafc9e60b60807188301f (diff) | |
| download | go-x-pkgsite-a72c2ab9ef763fea88a865dfb39feb6df9829580.tar.xz | |
internal/fetch: check for mismatched path
Read the go.mod file from the proxy, and check if its path differs
from the module path. If they do differ, fail with an
AlternativeModule error, and record the relationship between the two
paths in a table for future use.
This change means that the discovery site will not serve modules that:
- are case variants of the canonical path
e.g. github.com/Sirupsen/logrus vs. the correct github.com/sirupsen/logrus
- bypass the vanity import path
e.g. github.com/gonum/gonum vs. the correct gonum.org/v1/gonum
- are "soft forks" of the module's repo: forks with an unchanged go.mod path
e.g. github.com/alice02/kubernetes vs. the correct k8s.io/kubernetes
Change-Id: If78c94744440112f5720750885fe10f6a7dc7ab8
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/623922
Reviewed-by: Julie Qiu <julieqiu@google.com>
Diffstat (limited to 'internal/stdlib/stdlib.go')
| -rw-r--r-- | internal/stdlib/stdlib.go | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/internal/stdlib/stdlib.go b/internal/stdlib/stdlib.go index 9b9adb07..7b61c6b9 100644 --- a/internal/stdlib/stdlib.go +++ b/internal/stdlib/stdlib.go @@ -304,7 +304,6 @@ func Zip(version string) (_ *zip.Reader, commitTime time.Time, err error) { if err := addFiles(z, repo, libdir, prefixPath, true); err != nil { return nil, time.Time{}, err } - if err := z.Close(); err != nil { return nil, time.Time{}, err } @@ -323,21 +322,21 @@ func addFiles(z *zip.Writer, r *git.Repository, t *object.Tree, dirpath string, if strings.HasPrefix(e.Name, ".") || strings.HasPrefix(e.Name, "_") { continue } + if e.Name == "go.mod" { + // ignore; we'll synthesize our own + continue + } switch e.Mode { case filemode.Regular, filemode.Executable: blob, err := r.BlobObject(e.Hash) if err != nil { return err } - dst, err := z.Create(path.Join(dirpath, e.Name)) - if err != nil { - return err - } src, err := blob.Reader() if err != nil { return err } - if _, err := io.Copy(dst, src); err != nil { + if err := writeZipFile(z, path.Join(dirpath, e.Name), src); err != nil { _ = src.Close() return err } @@ -360,6 +359,15 @@ func addFiles(z *zip.Writer, r *git.Repository, t *object.Tree, dirpath string, return nil } +func writeZipFile(z *zip.Writer, pathname string, src io.Reader) error { + dst, err := z.Create(pathname) + if err != nil { + return err + } + _, err = io.Copy(dst, src) + return err +} + // subTree looks non-recursively for a directory with the given name in t, // and returns the corresponding tree. // If a directory with such name doesn't exist in t, it returns os.ErrNotExist. |
