style(main): remove alpmHandle

This commit is contained in:
jguer 2020-08-01 09:55:08 +02:00
parent 005b29373d
commit 94f650f4d3
No known key found for this signature in database
GPG Key ID: 6D6CC9BEA8556B35
7 changed files with 43 additions and 41 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v10/pkg/db"
"github.com/Jguer/yay/v10/pkg/dep"
"github.com/Jguer/yay/v10/pkg/query"
"github.com/Jguer/yay/v10/pkg/settings"
@ -65,7 +66,7 @@ func cleanRemove(cmdArgs *settings.Arguments, pkgNames []string) error {
return show(passToPacman(arguments))
}
func syncClean(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
func syncClean(cmdArgs *settings.Arguments, dbExecutor *db.AlpmExecutor) error {
keepInstalled := false
keepCurrent := false
@ -99,7 +100,7 @@ func syncClean(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
fmt.Println(gotext.Get("\nBuild directory:"), config.BuildDir)
if text.ContinueTask(question, true, config.NoConfirm) {
if err := cleanAUR(keepInstalled, keepCurrent, removeAll, alpmHandle); err != nil {
if err := cleanAUR(keepInstalled, keepCurrent, removeAll, dbExecutor); err != nil {
return err
}
}
@ -115,13 +116,13 @@ func syncClean(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
return nil
}
func cleanAUR(keepInstalled, keepCurrent, removeAll bool, alpmHandle *alpm.Handle) error {
func cleanAUR(keepInstalled, keepCurrent, removeAll bool, dbExecutor *db.AlpmExecutor) error {
fmt.Println(gotext.Get("removing AUR packages from cache..."))
installedBases := make(stringset.StringSet)
inAURBases := make(stringset.StringSet)
remotePackages, _ := query.GetRemotePackages(config.Runtime.DBExecutor)
remotePackages, _ := query.GetRemotePackages(dbExecutor)
files, err := ioutil.ReadDir(config.BuildDir)
if err != nil {

36
cmd.go
View File

@ -140,7 +140,7 @@ getpkgbuild specific options:
-f --force Force download for existing ABS packages`)
}
func handleCmd(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
func handleCmd(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecutor *db.AlpmExecutor) error {
if cmdArgs.ExistsArg("h", "help") {
return handleHelp(cmdArgs)
}
@ -158,11 +158,11 @@ func handleCmd(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
case "F", "files":
return show(passToPacman(cmdArgs))
case "Q", "query":
return handleQuery(cmdArgs, alpmHandle)
return handleQuery(cmdArgs, dbExecutor)
case "R", "remove":
return handleRemove(cmdArgs)
case "S", "sync":
return handleSync(cmdArgs, alpmHandle)
return handleSync(cmdArgs, alpmHandle, dbExecutor)
case "T", "deptest":
return show(passToPacman(cmdArgs))
case "U", "upgrade":
@ -170,17 +170,17 @@ func handleCmd(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
case "G", "getpkgbuild":
return handleGetpkgbuild(cmdArgs, alpmHandle)
case "P", "show":
return handlePrint(cmdArgs, alpmHandle, config.Runtime.DBExecutor)
return handlePrint(cmdArgs, alpmHandle, dbExecutor)
case "Y", "--yay":
return handleYay(cmdArgs, alpmHandle)
return handleYay(cmdArgs, alpmHandle, dbExecutor)
}
return fmt.Errorf(gotext.Get("unhandled operation"))
}
func handleQuery(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
func handleQuery(cmdArgs *settings.Arguments, dbExecutor *db.AlpmExecutor) error {
if cmdArgs.ExistsArg("u", "upgrades") {
return printUpdateList(cmdArgs, alpmHandle, cmdArgs.ExistsDouble("u", "sysupgrade"))
return printUpdateList(cmdArgs, dbExecutor, cmdArgs.ExistsDouble("u", "sysupgrade"))
}
return show(passToPacman(cmdArgs))
}
@ -227,7 +227,7 @@ func handlePrint(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecuto
case cmdArgs.ExistsArg("g", "currentconfig"):
fmt.Printf("%v", config)
case cmdArgs.ExistsArg("n", "numberupgrades"):
err = printNumberOfUpdates(alpmHandle, cmdArgs.ExistsDouble("u", "sysupgrade"))
err = printNumberOfUpdates(dbExecutor, cmdArgs.ExistsDouble("u", "sysupgrade"))
case cmdArgs.ExistsArg("w", "news"):
double := cmdArgs.ExistsDouble("w", "news")
quiet := cmdArgs.ExistsArg("q", "quiet")
@ -244,9 +244,9 @@ func handlePrint(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecuto
return err
}
func handleYay(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
func handleYay(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecutor *db.AlpmExecutor) error {
if cmdArgs.ExistsArg("gendb") {
return createDevelDB(config.Runtime.VCSPath, alpmHandle)
return createDevelDB(config.Runtime.VCSPath, dbExecutor)
}
if cmdArgs.ExistsDouble("c") {
return cleanDependencies(cmdArgs, alpmHandle, true)
@ -255,7 +255,7 @@ func handleYay(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
return cleanDependencies(cmdArgs, alpmHandle, false)
}
if len(cmdArgs.Targets) > 0 {
return handleYogurt(cmdArgs, alpmHandle)
return handleYogurt(cmdArgs, dbExecutor)
}
return nil
}
@ -264,12 +264,12 @@ func handleGetpkgbuild(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) err
return getPkgbuilds(cmdArgs.Targets, alpmHandle, cmdArgs.ExistsArg("f", "force"))
}
func handleYogurt(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
func handleYogurt(cmdArgs *settings.Arguments, dbExecutor *db.AlpmExecutor) error {
config.SearchMode = numberMenu
return displayNumberMenu(cmdArgs.Targets, alpmHandle, cmdArgs)
return displayNumberMenu(cmdArgs.Targets, dbExecutor, cmdArgs)
}
func handleSync(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
func handleSync(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecutor *db.AlpmExecutor) error {
targets := cmdArgs.Targets
if cmdArgs.ExistsArg("s", "search") {
@ -284,7 +284,7 @@ func handleSync(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
return show(passToPacman(cmdArgs))
}
if cmdArgs.ExistsArg("c", "clean") {
return syncClean(cmdArgs, alpmHandle)
return syncClean(cmdArgs, dbExecutor)
}
if cmdArgs.ExistsArg("l", "list") {
return syncList(cmdArgs, alpmHandle)
@ -317,7 +317,7 @@ func handleRemove(cmdArgs *settings.Arguments) error {
}
// NumberMenu presents a CLI for selecting packages to install.
func displayNumberMenu(pkgS []string, alpmHandle *alpm.Handle, cmdArgs *settings.Arguments) error {
func displayNumberMenu(pkgS []string, dbExecutor *db.AlpmExecutor, cmdArgs *settings.Arguments) error {
var (
aurErr, repoErr error
aq aurQuery
@ -332,7 +332,7 @@ func displayNumberMenu(pkgS []string, alpmHandle *alpm.Handle, cmdArgs *settings
lenaq = len(aq)
}
if config.Runtime.Mode == settings.ModeRepo || config.Runtime.Mode == settings.ModeAny {
pq = queryRepo(pkgS, config.Runtime.DBExecutor)
pq = queryRepo(pkgS, dbExecutor)
lenpq = len(pq)
if repoErr != nil {
return repoErr
@ -427,7 +427,7 @@ func displayNumberMenu(pkgS []string, alpmHandle *alpm.Handle, cmdArgs *settings
sudoLoopBackground()
}
return install(arguments, config.Runtime.DBExecutor, true)
return install(arguments, dbExecutor, true)
}
func syncList(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {

View File

@ -195,6 +195,6 @@ func main() {
exitOnError(err)
config.Runtime.DBExecutor, err = db.NewAlpmExecutor(config.Runtime.AlpmHandle, runtime.PacmanConf, questionCallback)
exitOnError(err)
exitOnError(handleCmd(cmdArgs, config.Runtime.AlpmHandle))
exitOnError(handleCmd(cmdArgs, config.Runtime.AlpmHandle, config.Runtime.DBExecutor))
os.Exit(cleanup(config.Runtime.AlpmHandle))
}

View File

@ -25,11 +25,8 @@ outer:
// GetRemotePackages returns packages with no correspondence in SyncDBS.
func GetRemotePackages(dbExecutor *db.AlpmExecutor) (
[]db.RepoPackage,
[]string) {
remoteNames := []string{}
remote := []db.RepoPackage{}
remote []db.RepoPackage,
remoteNames []string) {
outer:
for _, localpkg := range dbExecutor.LocalPackages() {
for _, syncpkg := range dbExecutor.SyncPackages() {
@ -47,14 +44,14 @@ func RemoveInvalidTargets(targets []string, mode settings.TargetMode) []string {
filteredTargets := make([]string, 0)
for _, target := range targets {
db, _ := text.SplitDBFromName(target)
dbName, _ := text.SplitDBFromName(target)
if db == "aur" && mode == settings.ModeRepo {
if dbName == "aur" && mode == settings.ModeRepo {
text.Warnln(gotext.Get("%s: can't use target with option --repo -- skipping", text.Cyan(target)))
continue
}
if db != "aur" && db != "" && mode == settings.ModeAUR {
if dbName != "aur" && dbName != "" && mode == settings.ModeAUR {
text.Warnln(gotext.Get("%s: can't use target with option --aur -- skipping", text.Cyan(target)))
continue
}

View File

@ -192,11 +192,11 @@ func localStatistics(alpmHandle *alpm.Handle) error {
}
// TODO: Make it less hacky
func printNumberOfUpdates(alpmHandle *alpm.Handle, enableDowngrade bool) error {
func printNumberOfUpdates(dbExecutor *db.AlpmExecutor, enableDowngrade bool) error {
warnings := query.NewWarnings()
old := os.Stdout // keep backup of the real stdout
os.Stdout = nil
aurUp, repoUp, err := upList(warnings, config.Runtime.DBExecutor, enableDowngrade)
aurUp, repoUp, err := upList(warnings, dbExecutor, enableDowngrade)
os.Stdout = old // restoring the real stdout
if err != nil {
return err
@ -207,17 +207,17 @@ func printNumberOfUpdates(alpmHandle *alpm.Handle, enableDowngrade bool) error {
}
// TODO: Make it less hacky
func printUpdateList(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, enableDowngrade bool) error {
func printUpdateList(cmdArgs *settings.Arguments, dbExecutor *db.AlpmExecutor, enableDowngrade bool) error {
targets := stringset.FromSlice(cmdArgs.Targets)
warnings := query.NewWarnings()
old := os.Stdout // keep backup of the real stdout
os.Stdout = nil
localNames, remoteNames, err := query.GetPackageNamesBySource(config.Runtime.DBExecutor)
localNames, remoteNames, err := query.GetPackageNamesBySource(dbExecutor)
if err != nil {
return err
}
aurUp, repoUp, err := upList(warnings, config.Runtime.DBExecutor, enableDowngrade)
aurUp, repoUp, err := upList(warnings, dbExecutor, enableDowngrade)
os.Stdout = old // restoring the real stdout
if err != nil {
return err

View File

@ -175,7 +175,12 @@ func upAUR(remote []db.RepoPackage, aurdata map[string]*rpc.Pkg) upgrade.UpSlice
if pkg.ShouldIgnore() {
printIgnoringPackage(pkg, aurPkg.Version)
} else {
toUpgrade = append(toUpgrade, upgrade.Upgrade{Name: aurPkg.Name, Repository: "aur", LocalVersion: pkg.Version(), RemoteVersion: aurPkg.Version})
toUpgrade = append(toUpgrade,
upgrade.Upgrade{
Name: aurPkg.Name,
Repository: "aur",
LocalVersion: pkg.Version(),
RemoteVersion: aurPkg.Version})
}
}
}

7
vcs.go
View File

@ -12,8 +12,7 @@ import (
gosrc "github.com/Morganamilo/go-srcinfo"
"github.com/leonelquinteros/gotext"
"github.com/Jguer/go-alpm"
"github.com/Jguer/yay/v10/pkg/db"
"github.com/Jguer/yay/v10/pkg/dep"
"github.com/Jguer/yay/v10/pkg/query"
"github.com/Jguer/yay/v10/pkg/stringset"
@ -32,11 +31,11 @@ type (
)
// createDevelDB forces yay to create a DB of the existing development packages
func createDevelDB(vcsFilePath string, alpmHandle *alpm.Handle) error {
func createDevelDB(vcsFilePath string, dbExecutor *db.AlpmExecutor) error {
var mux sync.Mutex
var wg sync.WaitGroup
_, remoteNames, err := query.GetPackageNamesBySource(config.Runtime.DBExecutor)
_, remoteNames, err := query.GetPackageNamesBySource(dbExecutor)
if err != nil {
return err
}