Skip to content

Commit eb1bf23

Browse files
zeripathlafriks
andauthored
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 <[email protected]> Co-authored-by: Lauris BH <[email protected]>
1 parent d3b5eda commit eb1bf23

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

modules/git/commit_archive.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package git
77

88
import (
9+
"context"
910
"fmt"
1011
"path/filepath"
1112
"strings"
@@ -39,7 +40,7 @@ type CreateArchiveOpts struct {
3940
}
4041

4142
// CreateArchive create archive content to the target path
42-
func (c *Commit) CreateArchive(target string, opts CreateArchiveOpts) error {
43+
func (c *Commit) CreateArchive(ctx context.Context, target string, opts CreateArchiveOpts) error {
4344
if opts.Format.String() == "unknown" {
4445
return fmt.Errorf("unknown format: %v", opts.Format)
4546
}
@@ -58,6 +59,6 @@ func (c *Commit) CreateArchive(target string, opts CreateArchiveOpts) error {
5859
c.ID.String(),
5960
)
6061

61-
_, err := NewCommand(args...).RunInDir(c.repo.Path)
62+
_, err := NewCommandContext(ctx, args...).RunInDir(c.repo.Path)
6263
return err
6364
}

routers/repo/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ func Download(ctx *context.Context) {
524524

525525
archivePath = path.Join(archivePath, base.ShortSha(commit.ID.String())+ext)
526526
if !com.IsFile(archivePath) {
527-
if err := commit.CreateArchive(archivePath, git.CreateArchiveOpts{
527+
if err := commit.CreateArchive(ctx.Req.Context(), archivePath, git.CreateArchiveOpts{
528528
Format: archiveType,
529529
Prefix: setting.Repository.PrefixArchiveFiles,
530530
}); err != nil {

0 commit comments

Comments
 (0)