fix: add download cancel via context and update progressbar

This commit is contained in:
2025-01-26 16:33:00 +03:00
parent dc1fac29d5
commit bba1ed52c5
11 changed files with 433 additions and 157 deletions

View File

@ -20,6 +20,7 @@
package dl
import (
"context"
"errors"
"net/url"
"path"
@ -47,7 +48,7 @@ func (GitDownloader) MatchURL(u string) bool {
// Download uses git to clone the repository from the specified URL.
// It allows specifying the revision, depth and recursion options
// via query string
func (GitDownloader) Download(opts Options) (Type, string, error) {
func (GitDownloader) Download(ctx context.Context, opts Options) (Type, string, error) {
u, err := url.Parse(opts.URL)
if err != nil {
return 0, "", err
@ -89,7 +90,7 @@ func (GitDownloader) Download(opts Options) (Type, string, error) {
co.RecurseSubmodules = git.DefaultSubmoduleRecursionDepth
}
r, err := git.PlainClone(opts.Destination, false, co)
r, err := git.PlainCloneContext(ctx, opts.Destination, false, co)
if err != nil {
return 0, "", err
}