1
0
mirror of https://github.com/Jguer/yay.git synced 2025-08-08 07:37:11 +02:00

feat(aur): add option to limit concurrent downloads (#1768)

* feat(aur): add option to limit concurrent downloads

Adds to config file option 'maxconcurrentdownloads' which if set to
value != 0, limits number of concurrent AUR downloads to specified.
Fixes #1763.

* fix lint issue
This commit is contained in:
vqrkxo 2022-06-28 12:05:29 +02:00 committed by GitHub
parent 18fbc24e68
commit e0006ec272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 113 additions and 100 deletions

View File

@ -65,7 +65,7 @@ func downloadPKGBUILDSourceWorker(ctx context.Context, wg *sync.WaitGroup, dest
} }
func downloadPKGBUILDSourceFanout(ctx context.Context, cmdBuilder exe.ICmdBuilder, dest string, func downloadPKGBUILDSourceFanout(ctx context.Context, cmdBuilder exe.ICmdBuilder, dest string,
bases []dep.Base, incompatible stringset.StringSet) error { bases []dep.Base, incompatible stringset.StringSet, maxConcurrentDownloads int) error {
if len(bases) == 1 { if len(bases) == 1 {
return downloadPKGBUILDSource(ctx, cmdBuilder, dest, bases[0].Pkgbase(), incompatible) return downloadPKGBUILDSource(ctx, cmdBuilder, dest, bases[0].Pkgbase(), incompatible)
} }
@ -78,6 +78,10 @@ func downloadPKGBUILDSourceFanout(ctx context.Context, cmdBuilder exe.ICmdBuilde
fanInChanErrors = make(chan error) fanInChanErrors = make(chan error)
) )
if maxConcurrentDownloads != 0 {
numOfWorkers = maxConcurrentDownloads
}
go func() { go func() {
for _, base := range bases { for _, base := range bases {
c <- base.Pkgbase() c <- base.Pkgbase()

View File

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"fmt"
"os/exec" "os/exec"
"sync/atomic" "sync/atomic"
"testing" "testing"
@ -82,13 +83,6 @@ func Test_downloadPKGBUILDSourceError(t *testing.T) {
// THEN 5 calls should be made to makepkg // THEN 5 calls should be made to makepkg
func Test_downloadPKGBUILDSourceFanout(t *testing.T) { func Test_downloadPKGBUILDSourceFanout(t *testing.T) {
t.Parallel() t.Parallel()
cmdBuilder := &TestMakepkgBuilder{
parentBuilder: &exe.CmdBuilder{
MakepkgConfPath: "/etc/not.conf",
MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg",
},
test: t,
}
bases := []dep.Base{ bases := []dep.Base{
{&aur.Pkg{PackageBase: "yay"}}, {&aur.Pkg{PackageBase: "yay"}},
@ -98,9 +92,21 @@ func Test_downloadPKGBUILDSourceFanout(t *testing.T) {
{&aur.Pkg{PackageBase: "yay-v12"}}, {&aur.Pkg{PackageBase: "yay-v12"}},
} }
err := downloadPKGBUILDSourceFanout(context.TODO(), cmdBuilder, "/tmp", bases, stringset.Make()) for _, maxConcurrentDownloads := range []int{0, 3} {
assert.NoError(t, err) t.Run(fmt.Sprintf("maxconcurrentdownloads set to %d", maxConcurrentDownloads), func(t *testing.T) {
assert.Equal(t, 5, int(cmdBuilder.passes)) cmdBuilder := &TestMakepkgBuilder{
parentBuilder: &exe.CmdBuilder{
MakepkgConfPath: "/etc/not.conf",
MakepkgFlags: []string{"--nocheck"}, MakepkgBin: "makepkg",
},
test: t,
}
err := downloadPKGBUILDSourceFanout(context.TODO(), cmdBuilder, "/tmp", bases, stringset.Make(), maxConcurrentDownloads)
assert.NoError(t, err)
assert.Equal(t, 5, int(cmdBuilder.passes))
})
}
} }
// GIVEN 1 package // GIVEN 1 package
@ -120,7 +126,7 @@ func Test_downloadPKGBUILDSourceFanoutNoCC(t *testing.T) {
{&aur.Pkg{PackageBase: "yay"}}, {&aur.Pkg{PackageBase: "yay"}},
} }
err := downloadPKGBUILDSourceFanout(context.TODO(), cmdBuilder, "/tmp", bases, stringset.Make()) err := downloadPKGBUILDSourceFanout(context.TODO(), cmdBuilder, "/tmp", bases, stringset.Make(), 0)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, 1, int(cmdBuilder.passes)) assert.Equal(t, 1, int(cmdBuilder.passes))
} }
@ -147,7 +153,7 @@ func Test_downloadPKGBUILDSourceFanoutError(t *testing.T) {
{&aur.Pkg{PackageBase: "yay-v12"}}, {&aur.Pkg{PackageBase: "yay-v12"}},
} }
err := downloadPKGBUILDSourceFanout(context.TODO(), cmdBuilder, "/tmp", bases, stringset.Make()) err := downloadPKGBUILDSourceFanout(context.TODO(), cmdBuilder, "/tmp", bases, stringset.Make(), 0)
assert.Error(t, err) assert.Error(t, err)
assert.Equal(t, 5, int(cmdBuilder.passes)) assert.Equal(t, 5, int(cmdBuilder.passes))
assert.Len(t, err.(*multierror.MultiError).Errors, 5) assert.Len(t, err.(*multierror.MultiError).Errors, 5)

View File

@ -330,7 +330,8 @@ func install(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Execu
config.AURURL, config.Runtime.CompletionPath, config.CompletionInterval, false) config.AURURL, config.Runtime.CompletionPath, config.CompletionInterval, false)
}() }()
if errP := downloadPKGBUILDSourceFanout(ctx, config.Runtime.CmdBuilder, config.BuildDir, do.Aur, incompatible); errP != nil { if errP := downloadPKGBUILDSourceFanout(ctx, config.Runtime.CmdBuilder, config.BuildDir,
do.Aur, incompatible, config.MaxConcurrentDownloads); errP != nil {
text.Errorln(errP) text.Errorln(errP)
} }

View File

@ -30,50 +30,51 @@ var NoConfirm = false
// Configuration stores yay's config. // Configuration stores yay's config.
type Configuration struct { type Configuration struct {
AURURL string `json:"aururl"` AURURL string `json:"aururl"`
BuildDir string `json:"buildDir"` BuildDir string `json:"buildDir"`
Editor string `json:"editor"` Editor string `json:"editor"`
EditorFlags string `json:"editorflags"` EditorFlags string `json:"editorflags"`
MakepkgBin string `json:"makepkgbin"` MakepkgBin string `json:"makepkgbin"`
MakepkgConf string `json:"makepkgconf"` MakepkgConf string `json:"makepkgconf"`
PacmanBin string `json:"pacmanbin"` PacmanBin string `json:"pacmanbin"`
PacmanConf string `json:"pacmanconf"` PacmanConf string `json:"pacmanconf"`
ReDownload string `json:"redownload"` ReDownload string `json:"redownload"`
ReBuild string `json:"rebuild"` ReBuild string `json:"rebuild"`
AnswerClean string `json:"answerclean"` AnswerClean string `json:"answerclean"`
AnswerDiff string `json:"answerdiff"` AnswerDiff string `json:"answerdiff"`
AnswerEdit string `json:"answeredit"` AnswerEdit string `json:"answeredit"`
AnswerUpgrade string `json:"answerupgrade"` AnswerUpgrade string `json:"answerupgrade"`
GitBin string `json:"gitbin"` GitBin string `json:"gitbin"`
GpgBin string `json:"gpgbin"` GpgBin string `json:"gpgbin"`
GpgFlags string `json:"gpgflags"` GpgFlags string `json:"gpgflags"`
MFlags string `json:"mflags"` MFlags string `json:"mflags"`
SortBy string `json:"sortby"` SortBy string `json:"sortby"`
SearchBy string `json:"searchby"` SearchBy string `json:"searchby"`
GitFlags string `json:"gitflags"` GitFlags string `json:"gitflags"`
RemoveMake string `json:"removemake"` RemoveMake string `json:"removemake"`
SudoBin string `json:"sudobin"` SudoBin string `json:"sudobin"`
SudoFlags string `json:"sudoflags"` SudoFlags string `json:"sudoflags"`
RequestSplitN int `json:"requestsplitn"` RequestSplitN int `json:"requestsplitn"`
CompletionInterval int `json:"completionrefreshtime"` CompletionInterval int `json:"completionrefreshtime"`
BottomUp bool `json:"bottomup"` MaxConcurrentDownloads int `json:"maxconcurrentdownloads"`
SudoLoop bool `json:"sudoloop"` BottomUp bool `json:"bottomup"`
TimeUpdate bool `json:"timeupdate"` SudoLoop bool `json:"sudoloop"`
Devel bool `json:"devel"` TimeUpdate bool `json:"timeupdate"`
CleanAfter bool `json:"cleanAfter"` Devel bool `json:"devel"`
Provides bool `json:"provides"` CleanAfter bool `json:"cleanAfter"`
PGPFetch bool `json:"pgpfetch"` Provides bool `json:"provides"`
UpgradeMenu bool `json:"upgrademenu"` PGPFetch bool `json:"pgpfetch"`
CleanMenu bool `json:"cleanmenu"` UpgradeMenu bool `json:"upgrademenu"`
DiffMenu bool `json:"diffmenu"` CleanMenu bool `json:"cleanmenu"`
EditMenu bool `json:"editmenu"` DiffMenu bool `json:"diffmenu"`
CombinedUpgrade bool `json:"combinedupgrade"` EditMenu bool `json:"editmenu"`
UseAsk bool `json:"useask"` CombinedUpgrade bool `json:"combinedupgrade"`
BatchInstall bool `json:"batchinstall"` UseAsk bool `json:"useask"`
SingleLineResults bool `json:"singlelineresults"` BatchInstall bool `json:"batchinstall"`
SeparateSources bool `json:"separatesources"` SingleLineResults bool `json:"singlelineresults"`
Runtime *Runtime `json:"-"` SeparateSources bool `json:"separatesources"`
Version string `json:"version"` Runtime *Runtime `json:"-"`
Version string `json:"version"`
} }
// SaveConfig writes yay config to file. // SaveConfig writes yay config to file.
@ -178,48 +179,49 @@ func (c *Configuration) setPrivilegeElevator() error {
func DefaultConfig(version string) *Configuration { func DefaultConfig(version string) *Configuration {
return &Configuration{ return &Configuration{
AURURL: "https://aur.archlinux.org", AURURL: "https://aur.archlinux.org",
BuildDir: os.ExpandEnv("$HOME/.cache/yay"), BuildDir: os.ExpandEnv("$HOME/.cache/yay"),
CleanAfter: false, CleanAfter: false,
Editor: "", Editor: "",
EditorFlags: "", EditorFlags: "",
Devel: false, Devel: false,
MakepkgBin: "makepkg", MakepkgBin: "makepkg",
MakepkgConf: "", MakepkgConf: "",
PacmanBin: "pacman", PacmanBin: "pacman",
PGPFetch: true, PGPFetch: true,
PacmanConf: "/etc/pacman.conf", PacmanConf: "/etc/pacman.conf",
GpgFlags: "", GpgFlags: "",
MFlags: "", MFlags: "",
GitFlags: "", GitFlags: "",
BottomUp: true, BottomUp: true,
CompletionInterval: 7, CompletionInterval: 7,
SortBy: "votes", MaxConcurrentDownloads: 0,
SearchBy: "name-desc", SortBy: "votes",
SudoLoop: false, SearchBy: "name-desc",
GitBin: "git", SudoLoop: false,
GpgBin: "gpg", GitBin: "git",
SudoBin: "sudo", GpgBin: "gpg",
SudoFlags: "", SudoBin: "sudo",
TimeUpdate: false, SudoFlags: "",
RequestSplitN: 150, TimeUpdate: false,
ReDownload: "no", RequestSplitN: 150,
ReBuild: "no", ReDownload: "no",
BatchInstall: false, ReBuild: "no",
AnswerClean: "", BatchInstall: false,
AnswerDiff: "", AnswerClean: "",
AnswerEdit: "", AnswerDiff: "",
AnswerUpgrade: "", AnswerEdit: "",
RemoveMake: "ask", AnswerUpgrade: "",
Provides: true, RemoveMake: "ask",
UpgradeMenu: true, Provides: true,
CleanMenu: true, UpgradeMenu: true,
DiffMenu: true, CleanMenu: true,
EditMenu: false, DiffMenu: true,
UseAsk: false, EditMenu: false,
CombinedUpgrade: false, UseAsk: false,
SeparateSources: true, CombinedUpgrade: false,
Version: version, SeparateSources: true,
Version: version,
} }
} }