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:
parent
18fbc24e68
commit
e0006ec272
@ -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()
|
||||||
|
@ -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} {
|
||||||
|
t.Run(fmt.Sprintf("maxconcurrentdownloads set to %d", maxConcurrentDownloads), func(t *testing.T) {
|
||||||
|
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.NoError(t, err)
|
||||||
assert.Equal(t, 5, int(cmdBuilder.passes))
|
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)
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ type Configuration struct {
|
|||||||
SudoFlags string `json:"sudoflags"`
|
SudoFlags string `json:"sudoflags"`
|
||||||
RequestSplitN int `json:"requestsplitn"`
|
RequestSplitN int `json:"requestsplitn"`
|
||||||
CompletionInterval int `json:"completionrefreshtime"`
|
CompletionInterval int `json:"completionrefreshtime"`
|
||||||
|
MaxConcurrentDownloads int `json:"maxconcurrentdownloads"`
|
||||||
BottomUp bool `json:"bottomup"`
|
BottomUp bool `json:"bottomup"`
|
||||||
SudoLoop bool `json:"sudoloop"`
|
SudoLoop bool `json:"sudoloop"`
|
||||||
TimeUpdate bool `json:"timeupdate"`
|
TimeUpdate bool `json:"timeupdate"`
|
||||||
@ -194,6 +195,7 @@ func DefaultConfig(version string) *Configuration {
|
|||||||
GitFlags: "",
|
GitFlags: "",
|
||||||
BottomUp: true,
|
BottomUp: true,
|
||||||
CompletionInterval: 7,
|
CompletionInterval: 7,
|
||||||
|
MaxConcurrentDownloads: 0,
|
||||||
SortBy: "votes",
|
SortBy: "votes",
|
||||||
SearchBy: "name-desc",
|
SearchBy: "name-desc",
|
||||||
SudoLoop: false,
|
SudoLoop: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user