Skip to content

Commit

Permalink
fix: fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jguer committed Nov 15, 2022
1 parent ae91898 commit f042713
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 65 deletions.
6 changes: 4 additions & 2 deletions aur_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -40,6 +40,7 @@ func (installer *Installer) RunPostInstallHooks(ctx context.Context) error {
errMulti.Add(err)
}
}

return errMulti.Return()
}

Expand Down Expand Up @@ -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}
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}()
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down
12 changes: 6 additions & 6 deletions local_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
28 changes: 3 additions & 25 deletions pkg/cmd/graph/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,27 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/Jguer/yay/v11/pkg/db/ialpm"
"github.com/Jguer/yay/v11/pkg/dep"
"github.com/Jguer/yay/v11/pkg/metadata"
"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 {
return err
}

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)
Expand Down
12 changes: 7 additions & 5 deletions pkg/dep/depGraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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]{
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/metadata/metadata_aur.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/query/aur_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/query/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/settings/pacman.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/Jguer/yay/v11/pkg/settings/parser"

pacmanconf "github.com/Morganamilo/go-pacmanconf"
"golang.org/x/term"
)
Expand Down
12 changes: 7 additions & 5 deletions pkg/topo/dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (g *Graph[T, V]) getAlias(node T) T {
if aliasNode, ok := g.alias[node]; ok {
return aliasNode
}

return node
}

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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{}

Expand Down Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down
Loading

0 comments on commit f042713

Please sign in to comment.