From f042713aaac68a2c5cdb8e051cd644359ef8c8d3 Mon Sep 17 00:00:00 2001 From: jguer Date: Tue, 15 Nov 2022 15:44:50 +0100 Subject: [PATCH] fix: fix linting errors --- aur_install.go | 6 ++++-- cmd.go | 1 + install.go | 9 ++++++++- local_install.go | 12 ++++++------ pkg/cmd/graph/main.go | 28 +++------------------------- pkg/dep/depGraph.go | 12 +++++++----- pkg/metadata/metadata_aur.go | 4 ++-- pkg/query/aur_info.go | 1 + pkg/query/source.go | 8 ++++---- pkg/settings/pacman.go | 1 + pkg/topo/dep.go | 12 +++++++----- pkg/upgrade/upgrade.go | 16 +++++++++------- preparer.go | 9 +++++++-- sync.go | 8 +++++--- upgrade.go | 10 +++++++--- 15 files changed, 72 insertions(+), 65 deletions(-) diff --git a/aur_install.go b/aur_install.go index b55a90d20..9869b6c33 100644 --- a/aur_install.go +++ b/aur_install.go @@ -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 { diff --git a/cmd.go b/cmd.go index 3259a86c8..474148365 100644 --- a/cmd.go +++ b/cmd.go @@ -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, diff --git a/install.go b/install.go index d1b3da115..5779c5883 100644 --- a/install.go +++ b/install.go @@ -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 } diff --git a/local_install.go b/local_install.go index 205320c6c..853695ccd 100644 --- a/local_install.go +++ b/local_install.go @@ -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) } diff --git a/pkg/cmd/graph/main.go b/pkg/cmd/graph/main.go index e0d5630b2..c52a4c9fc 100644 --- a/pkg/cmd/graph/main.go +++ b/pkg/cmd/graph/main.go @@ -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) diff --git a/pkg/dep/depGraph.go b/pkg/dep/depGraph.go index eb9855de3..d54af8679 100644 --- a/pkg/dep/depGraph.go +++ b/pkg/dep/depGraph.go @@ -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, diff --git a/pkg/metadata/metadata_aur.go b/pkg/metadata/metadata_aur.go index 60ff20e13..767b3cf69 100644 --- a/pkg/metadata/metadata_aur.go +++ b/pkg/metadata/metadata_aur.go @@ -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 { diff --git a/pkg/query/aur_info.go b/pkg/query/aur_info.go index 9761ee3e8..1d450b622 100644 --- a/pkg/query/aur_info.go +++ b/pkg/query/aur_info.go @@ -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) diff --git a/pkg/query/source.go b/pkg/query/source.go index 1452374ab..78bfe5dd9 100644 --- a/pkg/query/source.go +++ b/pkg/query/source.go @@ -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 { diff --git a/pkg/settings/pacman.go b/pkg/settings/pacman.go index b7bc909d3..9c1d4f323 100644 --- a/pkg/settings/pacman.go +++ b/pkg/settings/pacman.go @@ -5,6 +5,7 @@ import ( "os" "github.com/Jguer/yay/v11/pkg/settings/parser" + pacmanconf "github.com/Morganamilo/go-pacmanconf" "golang.org/x/term" ) diff --git a/pkg/topo/dep.go b/pkg/topo/dep.go index 4dd0f1f33..0b550ae7d 100644 --- a/pkg/topo/dep.go +++ b/pkg/topo/dep.go @@ -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 diff --git a/pkg/upgrade/upgrade.go b/pkg/upgrade/upgrade.go index 3f7e5dd62..6128b62ba 100644 --- a/pkg/upgrade/upgrade.go +++ b/pkg/upgrade/upgrade.go @@ -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) } diff --git a/preparer.go b/preparer.go index c5be94379..de1170aa6 100644 --- a/preparer.go +++ b/preparer.go @@ -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 } diff --git a/sync.go b/sync.go index dc12a5c99..465e4881d 100644 --- a/sync.go +++ b/sync.go @@ -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) } diff --git a/upgrade.go b/upgrade.go index d55ece73b..f8440cfbe 100644 --- a/upgrade.go +++ b/upgrade.go @@ -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