// 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.
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 != "" {
}
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
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
}
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,
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)
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)
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
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()
}
f, err := ioutil.TempFile("", "go-readzip-*.zip")
if err != nil {
- return nil, "", err
+ return nil, err
}
if r.cmd.vcs == "fossil" {
// If you run
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.
}
}
- 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-")