fix: fix linting errors

This commit is contained in:
jguer 2022-11-15 15:44:50 +01:00
parent ae918986f4
commit f042713aaa
No known key found for this signature in database
GPG Key ID: 6D6CC9BEA8556B35
15 changed files with 72 additions and 65 deletions

View File

@ -11,9 +11,9 @@ import (
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/settings/parser"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/leonelquinteros/gotext"
mapset "github.com/deckarep/golang-set/v2"
"github.com/leonelquinteros/gotext"
)
type (
@ -40,6 +40,7 @@ func (installer *Installer) RunPostInstallHooks(ctx context.Context) error {
errMulti.Add(err)
}
}
return errMulti.Return()
}
@ -195,7 +196,7 @@ func (*Installer) isDep(cmdArgs *parser.Arguments, aurExpNames mapset.Set[string
}
func (installer *Installer) getNewTargets(pkgdests map[string]string, name string,
) ([]string, bool, error) {
) (archives []string, good bool, err error) {
pkgdest, ok := pkgdests[name]
if !ok {
return nil, false, &PkgDestNotInListError{name: name}
@ -210,6 +211,7 @@ func (installer *Installer) getNewTargets(pkgdests map[string]string, name strin
pkgArchives = append(pkgArchives, pkgdest)
debugName := pkgdest + "-debug"
pkgdestDebug, ok := pkgdests[debugName]
if ok {
if _, errStat := os.Stat(pkgdestDebug); errStat == nil {

1
cmd.go
View File

@ -360,6 +360,7 @@ func handleSync(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Ex
if config.NewInstallEngine {
return syncInstall(ctx, config, cmdArgs, dbExecutor)
}
return install(ctx, cmdArgs, dbExecutor, false)
case cmdArgs.ExistsArg("y", "refresh"):
return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,

View File

@ -46,6 +46,7 @@ func setPkgReason(ctx context.Context, cmdArgs *parser.Arguments, pkgs []string,
for _, compositePkgName := range pkgs {
pkgSplit := strings.Split(compositePkgName, "/")
pkgName := pkgSplit[0]
if len(pkgSplit) > 1 {
pkgName = pkgSplit[1]
@ -132,6 +133,7 @@ func install(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Execu
// if we are doing -u also request all packages needing update
if sysupgradeArg {
var errSysUp error
requestTargets, errSysUp = addUpgradeTargetsToArgs(ctx, dbExecutor, cmdArgs, requestTargets, arguments)
if errSysUp != nil {
return errSysUp
@ -198,12 +200,14 @@ func install(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Execu
if config.CleanAfter {
defer func() {
pkgbuildDirs := make([]string, 0, len(do.Aur))
for _, base := range do.Aur {
dir := filepath.Join(config.BuildDir, base.Pkgbase())
if isGitRepository(dir) {
pkgbuildDirs = append(pkgbuildDirs, dir)
}
}
cleanAfter(ctx, config.Runtime.CmdBuilder, pkgbuildDirs)
}()
}
@ -357,7 +361,9 @@ func install(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Execu
return nil
}
func addUpgradeTargetsToArgs(ctx context.Context, dbExecutor db.Executor, cmdArgs *parser.Arguments, requestTargets []string, arguments *parser.Arguments) ([]string, error) {
func addUpgradeTargetsToArgs(ctx context.Context, dbExecutor db.Executor,
cmdArgs *parser.Arguments, requestTargets []string, arguments *parser.Arguments,
) ([]string, error) {
ignore, targets, errUp := sysupgradeTargets(ctx, dbExecutor, cmdArgs.ExistsDouble("u", "sysupgrade"))
if errUp != nil {
return nil, errUp
@ -371,6 +377,7 @@ func addUpgradeTargetsToArgs(ctx context.Context, dbExecutor db.Executor, cmdArg
if len(ignore) > 0 {
arguments.CreateOrAppendOption("ignore", ignore.ToSlice()...)
}
return requestTargets, nil
}

View File

@ -13,10 +13,10 @@ import (
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/settings/parser"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/leonelquinteros/gotext"
"github.com/pkg/errors"
gosrc "github.com/Morganamilo/go-srcinfo"
"github.com/leonelquinteros/gotext"
"github.com/pkg/errors"
)
var ErrInstallRepoPkgs = errors.New(gotext.Get("error installing repo packages"))
@ -65,11 +65,11 @@ func installLocalPKGBUILD(
}
installer := &Installer{dbExecutor: dbExecutor}
if err = preparer.Present(os.Stdout, topoSorted); err != nil {
return err
if errP := preparer.Present(os.Stdout, topoSorted); errP != nil {
return errP
}
if cleanFunc := preparer.ShouldCleanMakeDeps(ctx); cleanFunc != nil {
if cleanFunc := preparer.ShouldCleanMakeDeps(); cleanFunc != nil {
installer.AddPostInstallHook(cleanFunc)
}
@ -78,7 +78,7 @@ func installLocalPKGBUILD(
return err
}
if cleanAURDirsFunc := preparer.ShouldCleanAURDirs(ctx, pkgBuildDirs); cleanAURDirsFunc != nil {
if cleanAURDirsFunc := preparer.ShouldCleanAURDirs(pkgBuildDirs); cleanAURDirsFunc != nil {
installer.AddPostInstallHook(cleanAURDirsFunc)
}

View File

@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/Jguer/yay/v11/pkg/db/ialpm"
"github.com/Jguer/yay/v11/pkg/dep"
@ -13,32 +12,11 @@ import (
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/settings/parser"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/leonelquinteros/gotext"
"github.com/pkg/errors"
)
func splitDep(dep string) (pkg, mod, ver string) {
split := strings.FieldsFunc(dep, func(c rune) bool {
match := c == '>' || c == '<' || c == '='
if match {
mod += string(c)
}
return match
})
if len(split) == 0 {
return "", "", ""
}
if len(split) == 1 {
return split[0], "", ""
}
return split[0], mod, split[1]
}
func handleCmd() error {
config, err := settings.NewConfig("")
if err != nil {
@ -46,8 +24,8 @@ func handleCmd() error {
}
cmdArgs := parser.MakeArguments()
if err := config.ParseCommandLine(cmdArgs); err != nil {
return err
if errP := config.ParseCommandLine(cmdArgs); errP != nil {
return errP
}
pacmanConf, _, err := settings.RetrievePacmanConfig(cmdArgs, config.PacmanConf)

View File

@ -7,13 +7,13 @@ import (
"os"
"strconv"
aurc "github.com/Jguer/aur"
"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/metadata"
aur "github.com/Jguer/yay/v11/pkg/query"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/Jguer/yay/v11/pkg/topo"
aurc "github.com/Jguer/aur"
gosrc "github.com/Morganamilo/go-srcinfo"
"github.com/leonelquinteros/gotext"
)
@ -179,8 +179,8 @@ func (g *Grapher) GraphFromSrcInfo(ctx context.Context, graph *topo.Graph[string
return nil, err
}
for _, pkg := range aurPkgs {
pkg := pkg
for i := range aurPkgs {
pkg := &aurPkgs[i]
graph.AddNode(pkg.Name)
g.ValidateAndSetNodeInfo(graph, pkg.Name, &topo.NodeInfo[*InstallInfo]{
@ -195,7 +195,7 @@ func (g *Grapher) GraphFromSrcInfo(ctx context.Context, graph *topo.Graph[string
},
})
g.addDepNodes(ctx, &pkg, graph)
g.addDepNodes(ctx, pkg, graph)
}
return graph, nil
@ -447,7 +447,9 @@ func makeAURPKGFromSrcinfo(dbExecutor db.Executor, srcInfo *gosrc.Srcinfo) ([]au
alpmArch = append(alpmArch, "") // srcinfo assumes no value as ""
for _, pkg := range srcInfo.Packages {
for i := range srcInfo.Packages {
pkg := &srcInfo.Packages[i]
pkgs = append(pkgs, aur.Pkg{
ID: 0,
Name: pkg.Pkgname,

View File

@ -108,9 +108,9 @@ func (a *AURCache) gojqGetBatch(ctx context.Context, query *AURQuery) ([]*aur.Pk
bys := toSearchBy(query.By)
for j, by := range bys {
if query.Contains {
pattern += fmt.Sprintf("(.%s // empty | test(\"%s\"))", by, searchTerm)
pattern += fmt.Sprintf("(.%s // empty | test(%q))", by, searchTerm)
} else {
pattern += fmt.Sprintf("(.%s == \"%s\")", by, searchTerm)
pattern += fmt.Sprintf("(.%s == %q)", by, searchTerm)
}
if j != len(bys)-1 {

View File

@ -33,6 +33,7 @@ func AURInfo(ctx context.Context, aurClient aur.ClientInterface, names []string,
defer wg.Done()
text.Debugln("AUR RPC:", names[n:max])
tempInfo, requestErr := aurClient.Info(ctx, names[n:max])
if requestErr != nil {
errs.Add(requestErr)

View File

@ -204,7 +204,7 @@ func queryAUR(ctx context.Context,
var r []aur.Pkg
if aurMetadata != nil && newEngine {
q, err := aurMetadata.Get(ctx, &metadata.AURQuery{
q, errM := aurMetadata.Get(ctx, &metadata.AURQuery{
Needles: []string{word},
By: by,
Contains: true,
@ -214,11 +214,11 @@ func queryAUR(ctx context.Context,
r = append(r, *pkg)
}
if err == nil {
if errM == nil {
return r, nil
} else {
text.Warnln("AUR Metadata search failed:", err)
}
text.Warnln("AUR Metadata search failed:", err)
}
// if one of the search terms returns a result we start filtering by it
if aurClient != nil {

View File

@ -5,6 +5,7 @@ import (
"os"
"github.com/Jguer/yay/v11/pkg/settings/parser"
pacmanconf "github.com/Morganamilo/go-pacmanconf"
"golang.org/x/term"
)

View File

@ -85,6 +85,7 @@ func (g *Graph[T, V]) getAlias(node T) T {
if aliasNode, ok := g.alias[node]; ok {
return aliasNode
}
return node
}
@ -136,6 +137,7 @@ func (g *Graph[T, V]) DependOn(child, parent T) error {
func (g *Graph[T, V]) String() string {
var sb strings.Builder
sb.WriteString("digraph {\n")
sb.WriteString("compound=true;\n")
sb.WriteString("concentrate=true;\n")
@ -231,7 +233,7 @@ func (g *Graph[T, V]) TopoSortedLayers() [][]T {
return layers
}
// TopoSortedLayerMap returns a slice of all of the graph nodes in topological sort order with their node info
// TopoSortedLayerMap returns a slice of all of the graph nodes in topological sort order with their node info.
func (g *Graph[T, V]) TopoSortedLayerMap() []map[T]V {
layers := []map[T]V{}
@ -370,10 +372,10 @@ func (s NodeSet[T]) copy() NodeSet[T] {
return out
}
func (m DepMap[T]) copy() DepMap[T] {
out := make(DepMap[T], len(m))
for k, v := range m {
out[k] = v.copy()
func (dm DepMap[T]) copy() DepMap[T] {
out := make(DepMap[T], len(dm))
for k := range dm {
out[k] = dm[k].copy()
}
return out

View File

@ -15,7 +15,7 @@ type Filter func(Upgrade) bool
// Upgrade type describes a system upgrade.
type Upgrade = db.Upgrade
func StylizedNameWithRepository(u Upgrade) string {
func StylizedNameWithRepository(u *Upgrade) string {
return text.Bold(text.ColorHash(u.Repository)) + "/" + text.Bold(u.Name)
}
@ -103,9 +103,10 @@ func GetVersionDiff(oldVersion, newVersion string) (left, right string) {
func (u UpSlice) Print() {
longestName, longestVersion := 0, 0
for _, pack := range u.Up {
packNameLen := len(StylizedNameWithRepository(pack))
packVersion, _ := GetVersionDiff(pack.LocalVersion, pack.RemoteVersion)
for k := range u.Up {
upgrade := &u.Up[k]
packNameLen := len(StylizedNameWithRepository(upgrade))
packVersion, _ := GetVersionDiff(upgrade.LocalVersion, upgrade.RemoteVersion)
packVersionLen := len(packVersion)
longestName = intrange.Max(packNameLen, longestName)
longestVersion = intrange.Max(packVersionLen, longestVersion)
@ -115,12 +116,13 @@ func (u UpSlice) Print() {
versionPadding := fmt.Sprintf("%%-%ds", longestVersion)
numberPadding := fmt.Sprintf("%%%dd ", len(fmt.Sprintf("%v", len(u.Up))))
for k, i := range u.Up {
left, right := GetVersionDiff(i.LocalVersion, i.RemoteVersion)
for k := range u.Up {
upgrade := &u.Up[k]
left, right := GetVersionDiff(upgrade.LocalVersion, upgrade.RemoteVersion)
fmt.Print(text.Magenta(fmt.Sprintf(numberPadding, len(u.Up)-k)))
fmt.Printf(namePadding, StylizedNameWithRepository(i))
fmt.Printf(namePadding, StylizedNameWithRepository(upgrade))
fmt.Printf("%s -> %s\n", fmt.Sprintf(versionPadding, left), right)
}

View File

@ -14,6 +14,7 @@ import (
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/settings/exe"
"github.com/Jguer/yay/v11/pkg/text"
mapset "github.com/deckarep/golang-set/v2"
"github.com/leonelquinteros/gotext"
)
@ -26,7 +27,7 @@ type Preparer struct {
makeDeps []string
}
func (preper *Preparer) ShouldCleanAURDirs(ctx context.Context, pkgBuildDirs map[string]string) PostInstallHookFunc {
func (preper *Preparer) ShouldCleanAURDirs(pkgBuildDirs map[string]string) PostInstallHookFunc {
if !preper.config.CleanAfter {
return nil
}
@ -37,13 +38,14 @@ func (preper *Preparer) ShouldCleanAURDirs(ctx context.Context, pkgBuildDirs map
}
text.Debugln("added post install hook to clean up AUR dirs", dirs)
return func(ctx context.Context) error {
cleanAfter(ctx, preper.config.Runtime.CmdBuilder, dirs)
return nil
}
}
func (preper *Preparer) ShouldCleanMakeDeps(ctx context.Context) PostInstallHookFunc {
func (preper *Preparer) ShouldCleanMakeDeps() PostInstallHookFunc {
if len(preper.makeDeps) == 0 {
return nil
}
@ -60,6 +62,7 @@ func (preper *Preparer) ShouldCleanMakeDeps(ctx context.Context) PostInstallHook
}
text.Debugln("added post install hook to clean up AUR makedeps", preper.makeDeps)
return func(ctx context.Context) error {
return removeMake(ctx, preper.config.Runtime.CmdBuilder, preper.makeDeps)
}
@ -85,6 +88,7 @@ func (preper *Preparer) Present(w io.Writer, targets []map[string]*dep.InstallIn
}
pkgsBySourceAndReason[source][reason] = append(pkgsBySourceAndReason[source][reason], pkgStr)
if info.Reason == dep.MakeDep {
preper.makeDeps = append(preper.makeDeps, pkgName)
}
@ -129,5 +133,6 @@ func (preper *Preparer) PrepareWorkspace(ctx context.Context, targets []map[stri
pkgBuildDirs, false, config.MaxConcurrentDownloads); errP != nil {
text.Errorln(errP)
}
return pkgBuildDirs, nil
}

View File

@ -10,6 +10,7 @@ import (
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/settings/parser"
"github.com/Jguer/yay/v11/pkg/text"
"github.com/leonelquinteros/gotext"
)
@ -42,6 +43,7 @@ func syncInstall(ctx context.Context,
if cmdArgs.ExistsArg("u", "sysupgrade") {
var errSysUp error
graph, _, errSysUp = sysupgradeTargetsV2(ctx, aurCache, dbExecutor, graph, cmdArgs.ExistsDouble("u", "sysupgrade"))
if errSysUp != nil {
return errSysUp
@ -57,11 +59,11 @@ func syncInstall(ctx context.Context,
}
installer := &Installer{dbExecutor: dbExecutor}
if err = preparer.Present(os.Stdout, topoSorted); err != nil {
return err
if errP := preparer.Present(os.Stdout, topoSorted); errP != nil {
return errP
}
cleanFunc := preparer.ShouldCleanMakeDeps(ctx)
cleanFunc := preparer.ShouldCleanMakeDeps()
if cleanFunc != nil {
installer.AddPostInstallHook(cleanFunc)
}

View File

@ -78,6 +78,7 @@ func upList(ctx context.Context, aurCache *metadata.AURCache,
} else {
_aurdata, err = query.AURInfo(ctx, config.Runtime.AURClient, remoteNames, warnings, config.RequestSplitN)
}
errs.Add(err)
if err == nil {
@ -274,6 +275,7 @@ func sysupgradeTargetsV2(ctx context.Context,
}
warnings.Print()
ignore := make(stringset.StringSet)
allUpLen := len(repoUp.Up) + len(aurUp.Up)
@ -302,7 +304,8 @@ func sysupgradeTargetsV2(ctx context.Context,
isInclude := len(exclude) == 0 && len(otherExclude) == 0
for i, pkg := range repoUp.Up {
for i := range repoUp.Up {
pkg := &repoUp.Up[i]
if isInclude && otherInclude.Get(pkg.Repository) {
ignore.Set(pkg.Name)
}
@ -320,7 +323,8 @@ func sysupgradeTargetsV2(ctx context.Context,
ignore.Set(pkg.Name)
}
for i, pkg := range aurUp.Up {
for i := range aurUp.Up {
pkg := &aurUp.Up[i]
if isInclude && otherInclude.Get(pkg.Repository) {
continue
}
@ -337,7 +341,7 @@ func sysupgradeTargetsV2(ctx context.Context,
return graph, ignore, err
}
func addUpgradeToGraph(pkg db.Upgrade, graph *topo.Graph[string, *dep.InstallInfo]) {
func addUpgradeToGraph(pkg *db.Upgrade, graph *topo.Graph[string, *dep.InstallInfo]) {
source := dep.Sync
if pkg.Repository == "aur" {
source = dep.AUR