Set context for running CreateArchive in to that of the request (#12555)

Set the context for CreateArchive to that of the request to ensure that archives
are only built for as long as a request is requesting them

Fix #11551

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
zeripath 2020-08-28 07:55:12 +01:00 committed by GitHub
parent d3b5edacb6
commit eb1bf2377b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -6,6 +6,7 @@
package git package git
import ( import (
"context"
"fmt" "fmt"
"path/filepath" "path/filepath"
"strings" "strings"
@ -39,7 +40,7 @@ type CreateArchiveOpts struct {
} }
// CreateArchive create archive content to the target path // CreateArchive create archive content to the target path
func (c *Commit) CreateArchive(target string, opts CreateArchiveOpts) error { func (c *Commit) CreateArchive(ctx context.Context, target string, opts CreateArchiveOpts) error {
if opts.Format.String() == "unknown" { if opts.Format.String() == "unknown" {
return fmt.Errorf("unknown format: %v", opts.Format) return fmt.Errorf("unknown format: %v", opts.Format)
} }
@ -58,6 +59,6 @@ func (c *Commit) CreateArchive(target string, opts CreateArchiveOpts) error {
c.ID.String(), c.ID.String(),
) )
_, err := NewCommand(args...).RunInDir(c.repo.Path) _, err := NewCommandContext(ctx, args...).RunInDir(c.repo.Path)
return err return err
} }

View File

@ -524,7 +524,7 @@ func Download(ctx *context.Context) {
archivePath = path.Join(archivePath, base.ShortSha(commit.ID.String())+ext) archivePath = path.Join(archivePath, base.ShortSha(commit.ID.String())+ext)
if !com.IsFile(archivePath) { if !com.IsFile(archivePath) {
if err := commit.CreateArchive(archivePath, git.CreateArchiveOpts{ if err := commit.CreateArchive(ctx.Req.Context(), archivePath, git.CreateArchiveOpts{
Format: archiveType, Format: archiveType,
Prefix: setting.Repository.PrefixArchiveFiles, Prefix: setting.Repository.PrefixArchiveFiles,
}); err != nil { }); err != nil {