]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modfetch/codehost: remove invariantly-empty return value from Repo...
authorBryan C. Mills <bcmills@google.com>
Thu, 24 Oct 2019 19:17:16 +0000 (15:17 -0400)
committerBryan C. Mills <bcmills@google.com>
Thu, 24 Oct 2019 20:19:06 +0000 (20:19 +0000)
Previously, codehost.Repo.ReadZip returned an 'actualSubdir' value
that was the empty string in all current implementations.

Updates #26092

Change-Id: I6708dd0f13ba88bcf1a1fb405e9d818fd6f9197e
Reviewed-on: https://go-review.googlesource.com/c/go/+/203277
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/internal/modfetch/codehost/codehost.go
src/cmd/go/internal/modfetch/codehost/git.go
src/cmd/go/internal/modfetch/codehost/git_test.go
src/cmd/go/internal/modfetch/codehost/shell.go
src/cmd/go/internal/modfetch/codehost/vcs.go
src/cmd/go/internal/modfetch/coderepo.go

index a4e50d692a329c8ada084dd93b30af9993b59f3b..5867288c9669cf1ac22d8d8ef36dfa6ec051e6a6 100644 (file)
@@ -73,11 +73,10 @@ type Repo interface {
        // ReadZip downloads a zip file for the subdir subdirectory
        // of the given revision to a new file in a given temporary directory.
        // It should refuse to read more than maxSize bytes.
-       // It returns a ReadCloser for a streamed copy of the zip file,
-       // along with the actual subdirectory (possibly shorter than subdir)
-       // contained in the zip file. All files in the zip file are expected to be
+       // It returns a ReadCloser for a streamed copy of the zip file.
+       // All files in the zip file are expected to be
        // nested in a single top-level directory, whose name is not specified.
-       ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser, actualSubdir string, err error)
+       ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser, err error)
 
        // RecentTag returns the most recent tag on rev or one of its predecessors
        // with the given prefix and major version.
index 64d4573c7109b5854037f5f4a98e75258c82a708..4a08f8ded61947b5001e6841c91bfc847287803b 100644 (file)
@@ -795,7 +795,7 @@ func (r *gitRepo) DescendsFrom(rev, tag string) (bool, error) {
        return false, err
 }
 
-func (r *gitRepo) ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser, actualSubdir string, err error) {
+func (r *gitRepo) ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser, err error) {
        // TODO: Use maxSize or drop it.
        args := []string{}
        if subdir != "" {
@@ -803,17 +803,17 @@ func (r *gitRepo) ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser,
        }
        info, err := r.Stat(rev) // download rev into local git repo
        if err != nil {
-               return nil, "", err
+               return nil, err
        }
 
        unlock, err := r.mu.Lock()
        if err != nil {
-               return nil, "", err
+               return nil, err
        }
        defer unlock()
 
        if err := ensureGitAttributes(r.dir); err != nil {
-               return nil, "", err
+               return nil, err
        }
 
        // Incredibly, git produces different archives depending on whether
@@ -824,12 +824,12 @@ func (r *gitRepo) ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser,
        archive, err := Run(r.dir, "git", "-c", "core.autocrlf=input", "-c", "core.eol=lf", "archive", "--format=zip", "--prefix=prefix/", info.Name, args)
        if err != nil {
                if bytes.Contains(err.(*RunError).Stderr, []byte("did not match any files")) {
-                       return nil, "", os.ErrNotExist
+                       return nil, os.ErrNotExist
                }
-               return nil, "", err
+               return nil, err
        }
 
-       return ioutil.NopCloser(bytes.NewReader(archive)), "", nil
+       return ioutil.NopCloser(bytes.NewReader(archive)), nil
 }
 
 // ensureGitAttributes makes sure export-subst and export-ignore features are
index da9e7050407e86a4cc8f3eef6c5214ea3ad38ab0..39c904f92cde1bf4fb6ee872ba99dd964ef9d155 100644 (file)
@@ -246,12 +246,11 @@ func TestReadFile(t *testing.T) {
 }
 
 var readZipTests = []struct {
-       repo         string
-       rev          string
-       subdir       string
-       actualSubdir string
-       err          string
-       files        map[string]uint64
+       repo   string
+       rev    string
+       subdir string
+       err    string
+       files  map[string]uint64
 }{
        {
                repo:   gitrepo1,
@@ -408,7 +407,7 @@ func TestReadZip(t *testing.T) {
                        if err != nil {
                                t.Fatal(err)
                        }
-                       rc, actualSubdir, err := r.ReadZip(tt.rev, tt.subdir, 100000)
+                       rc, err := r.ReadZip(tt.rev, tt.subdir, 100000)
                        if err != nil {
                                if tt.err == "" {
                                        t.Fatalf("ReadZip: unexpected error %v", err)
@@ -425,9 +424,6 @@ func TestReadZip(t *testing.T) {
                        if tt.err != "" {
                                t.Fatalf("ReadZip: no error, wanted %v", tt.err)
                        }
-                       if actualSubdir != tt.actualSubdir {
-                               t.Fatalf("ReadZip: actualSubdir = %q, want %q", actualSubdir, tt.actualSubdir)
-                       }
                        zipdata, err := ioutil.ReadAll(rc)
                        if err != nil {
                                t.Fatal(err)
index 7b813c37401c8785ee12681036ed164af376a5fe..835bc53c0ddec138e44b747640f2853fe38d5798 100644 (file)
@@ -109,7 +109,7 @@ func main() {
                        if subdir == "-" {
                                subdir = ""
                        }
-                       rc, _, err := repo.ReadZip(f[1], subdir, 10<<20)
+                       rc, err := repo.ReadZip(f[1], subdir, 10<<20)
                        if err != nil {
                                fmt.Fprintf(os.Stderr, "?%s\n", err)
                                continue
index 48238f176c6dae63b0f09c1d76e966df2c9feee2..c9f77bf3b2da019c36b6a1f57ce67265346743ad 100644 (file)
@@ -417,14 +417,14 @@ func (r *vcsRepo) DescendsFrom(rev, tag string) (bool, error) {
        return false, vcsErrorf("DescendsFrom not implemented")
 }
 
-func (r *vcsRepo) ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser, actualSubdir string, err error) {
+func (r *vcsRepo) ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser, err error) {
        if r.cmd.readZip == nil {
-               return nil, "", vcsErrorf("ReadZip not implemented for %s", r.cmd.vcs)
+               return nil, vcsErrorf("ReadZip not implemented for %s", r.cmd.vcs)
        }
 
        unlock, err := r.mu.Lock()
        if err != nil {
-               return nil, "", err
+               return nil, err
        }
        defer unlock()
 
@@ -433,7 +433,7 @@ func (r *vcsRepo) ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser,
        }
        f, err := ioutil.TempFile("", "go-readzip-*.zip")
        if err != nil {
-               return nil, "", err
+               return nil, err
        }
        if r.cmd.vcs == "fossil" {
                // If you run
@@ -454,9 +454,9 @@ func (r *vcsRepo) ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser,
        if err != nil {
                f.Close()
                os.Remove(f.Name())
-               return nil, "", err
+               return nil, err
        }
-       return &deleteCloser{f}, "", nil
+       return &deleteCloser{f}, nil
 }
 
 // deleteCloser is a file that gets deleted on Close.
index 588f7a8d67c3ba9ac8b8c60cee3dd91c4f19527c..600b2e75c3e4c95ce299b42417b124d7db8bac4d 100644 (file)
@@ -780,19 +780,16 @@ func (r *codeRepo) Zip(dst io.Writer, version string) error {
                }
        }
 
-       rev, dir, _, err := r.findDir(version)
+       rev, subdir, _, err := r.findDir(version)
        if err != nil {
                return err
        }
-       dl, actualDir, err := r.code.ReadZip(rev, dir, codehost.MaxZipFile)
+       dl, err := r.code.ReadZip(rev, subdir, codehost.MaxZipFile)
        if err != nil {
                return err
        }
        defer dl.Close()
-       if actualDir != "" && !hasPathPrefix(dir, actualDir) {
-               return fmt.Errorf("internal error: downloading %v %v: dir=%q but actualDir=%q", r.modPath, rev, dir, actualDir)
-       }
-       subdir := strings.Trim(strings.TrimPrefix(dir, actualDir), "/")
+       subdir = strings.Trim(subdir, "/")
 
        // Spool to local file.
        f, err := ioutil.TempFile("", "go-codehost-")