Skip to content

Commit

Permalink
fix(sync_list): remove alpmHandle
Browse files Browse the repository at this point in the history
wip
  • Loading branch information
Jguer committed Aug 16, 2020
1 parent 6b973c6 commit f3925e2
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 206 deletions.
45 changes: 9 additions & 36 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net/http"
"os"
"time"

alpm "github.com/Jguer/go-alpm"
"github.com/leonelquinteros/gotext"
Expand Down Expand Up @@ -140,7 +139,7 @@ getpkgbuild specific options:
-f --force Force download for existing ABS packages`)
}

func handleCmd(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecutor *db.AlpmExecutor) error {
func handleCmd(cmdArgs *settings.Arguments, dbExecutor *db.AlpmExecutor) error {
if cmdArgs.ExistsArg("h", "help") {
return handleHelp(cmdArgs)
}
Expand All @@ -162,15 +161,15 @@ func handleCmd(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecutor
case "R", "remove":
return handleRemove(cmdArgs)
case "S", "sync":
return handleSync(cmdArgs, alpmHandle, dbExecutor)
return handleSync(cmdArgs, dbExecutor)
case "T", "deptest":
return show(passToPacman(cmdArgs))
case "U", "upgrade":
return show(passToPacman(cmdArgs))
case "G", "getpkgbuild":
return handleGetpkgbuild(cmdArgs, dbExecutor)
case "P", "show":
return handlePrint(cmdArgs, alpmHandle, dbExecutor)
return handlePrint(cmdArgs, dbExecutor)
case "Y", "--yay":
return handleYay(cmdArgs, dbExecutor)
}
Expand All @@ -197,28 +196,7 @@ func handleVersion() {
fmt.Printf("yay v%s - libalpm v%s\n", yayVersion, alpm.Version())
}

func lastBuildTime(alpmHandle *alpm.Handle) time.Time {
dbList, err := alpmHandle.SyncDBs()
if err != nil {
return time.Now()
}

var lastTime time.Time
_ = dbList.ForEach(func(db alpm.DB) error {
_ = db.PkgCache().ForEach(func(pkg alpm.Package) error {
thisTime := pkg.BuildDate()
if thisTime.After(lastTime) {
lastTime = thisTime
}
return nil
})
return nil
})

return lastTime
}

func handlePrint(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecutor *db.AlpmExecutor) (err error) {
func handlePrint(cmdArgs *settings.Arguments, dbExecutor *db.AlpmExecutor) (err error) {
switch {
case cmdArgs.ExistsArg("d", "defaultconfig"):
tmpConfig := settings.MakeConfig()
Expand All @@ -231,7 +209,7 @@ func handlePrint(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecuto
case cmdArgs.ExistsArg("w", "news"):
double := cmdArgs.ExistsDouble("w", "news")
quiet := cmdArgs.ExistsArg("q", "quiet")
err = news.PrintNewsFeed(lastBuildTime(alpmHandle), config.SortMode, double, quiet)
err = news.PrintNewsFeed(dbExecutor.LastBuildTime(), config.SortMode, double, quiet)
case cmdArgs.ExistsDouble("c", "complete"):
err = completion.Show(dbExecutor, config.AURURL, config.Runtime.CompletionPath, config.CompletionInterval, true)
case cmdArgs.ExistsArg("c", "complete"):
Expand Down Expand Up @@ -269,7 +247,7 @@ func handleYogurt(cmdArgs *settings.Arguments, dbExecutor *db.AlpmExecutor) erro
return displayNumberMenu(cmdArgs.Targets, dbExecutor, cmdArgs)
}

func handleSync(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecutor *db.AlpmExecutor) error {
func handleSync(cmdArgs *settings.Arguments, dbExecutor *db.AlpmExecutor) error {
targets := cmdArgs.Targets

if cmdArgs.ExistsArg("s", "search") {
Expand All @@ -287,7 +265,7 @@ func handleSync(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecutor
return syncClean(cmdArgs, dbExecutor)
}
if cmdArgs.ExistsArg("l", "list") {
return syncList(cmdArgs, alpmHandle)
return syncList(cmdArgs, dbExecutor)
}
if cmdArgs.ExistsArg("g", "groups") {
return show(passToPacman(cmdArgs))
Expand Down Expand Up @@ -430,7 +408,7 @@ func displayNumberMenu(pkgS []string, dbExecutor *db.AlpmExecutor, cmdArgs *sett
return install(arguments, dbExecutor, true)
}

func syncList(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
func syncList(cmdArgs *settings.Arguments, dbExecutor *db.AlpmExecutor) error {
aur := false

for i := len(cmdArgs.Targets) - 1; i >= 0; i-- {
Expand All @@ -441,11 +419,6 @@ func syncList(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
}

if (config.Runtime.Mode == settings.ModeAny || config.Runtime.Mode == settings.ModeAUR) && (len(cmdArgs.Targets) == 0 || aur) {
localDB, err := alpmHandle.LocalDB()
if err != nil {
return err
}

resp, err := http.Get(config.AURURL + "/packages.gz")
if err != nil {
return err
Expand All @@ -462,7 +435,7 @@ func syncList(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
} else {
fmt.Printf("%s %s %s", magenta("aur"), bold(name), bold(green(gotext.Get("unknown-version"))))

if localDB.Pkg(name) != nil {
if dbExecutor.LocalPackage(name) != nil {
fmt.Print(bold(blue(gotext.Get(" [Installed]"))))
}

Expand Down
101 changes: 0 additions & 101 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"os/exec"
"strings"

alpm "github.com/Jguer/go-alpm"
"github.com/Morganamilo/go-pacmanconf"
"github.com/leonelquinteros/gotext"

"github.com/Jguer/yay/v10/pkg/settings"
Expand Down Expand Up @@ -111,102 +109,3 @@ func getInput(defaultValue string) (string, error) {

return string(buf), nil
}

func toUsage(usages []string) alpm.Usage {
if len(usages) == 0 {
return alpm.UsageAll
}

var ret alpm.Usage
for _, usage := range usages {
switch usage {
case "Sync":
ret |= alpm.UsageSync
case "Search":
ret |= alpm.UsageSearch
case "Install":
ret |= alpm.UsageInstall
case "Upgrade":
ret |= alpm.UsageUpgrade
case "All":
ret |= alpm.UsageAll
}
}

return ret
}

func configureAlpm(pacmanConf *pacmanconf.Config, alpmHandle *alpm.Handle) error {
// TODO: set SigLevel
// sigLevel := alpm.SigPackage | alpm.SigPackageOptional | alpm.SigDatabase | alpm.SigDatabaseOptional
// localFileSigLevel := alpm.SigUseDefault
// remoteFileSigLevel := alpm.SigUseDefault

for _, repo := range pacmanConf.Repos {
// TODO: set SigLevel
db, err := alpmHandle.RegisterSyncDB(repo.Name, 0)
if err != nil {
return err
}

db.SetServers(repo.Servers)
db.SetUsage(toUsage(repo.Usage))
}

if err := alpmHandle.SetCacheDirs(pacmanConf.CacheDir); err != nil {
return err
}

// add hook directories 1-by-1 to avoid overwriting the system directory
for _, dir := range pacmanConf.HookDir {
if err := alpmHandle.AddHookDir(dir); err != nil {
return err
}
}

if err := alpmHandle.SetGPGDir(pacmanConf.GPGDir); err != nil {
return err
}

if err := alpmHandle.SetLogFile(pacmanConf.LogFile); err != nil {
return err
}

if err := alpmHandle.SetIgnorePkgs(pacmanConf.IgnorePkg); err != nil {
return err
}

if err := alpmHandle.SetIgnoreGroups(pacmanConf.IgnoreGroup); err != nil {
return err
}

if err := alpmHandle.SetArch(pacmanConf.Architecture); err != nil {
return err
}

if err := alpmHandle.SetNoUpgrades(pacmanConf.NoUpgrade); err != nil {
return err
}

if err := alpmHandle.SetNoExtracts(pacmanConf.NoExtract); err != nil {
return err
}

/*if err := alpmHandle.SetDefaultSigLevel(sigLevel); err != nil {
return err
}
if err := alpmHandle.SetLocalFileSigLevel(localFileSigLevel); err != nil {
return err
}
if err := alpmHandle.SetRemoteFileSigLevel(remoteFileSigLevel); err != nil {
return err
}*/

if err := alpmHandle.SetUseSyslog(pacmanConf.UseSyslog); err != nil {
return err
}

return alpmHandle.SetCheckSpace(pacmanConf.CheckSpace)
}
4 changes: 3 additions & 1 deletion install.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ func install(cmdArgs *settings.Arguments, dbExecutor *db.AlpmExecutor, ignorePro
}
}

go exitOnError(completion.Update(dbExecutor, config.AURURL, config.Runtime.CompletionPath, config.CompletionInterval, false))
go func() {
_ = completion.Update(dbExecutor, config.AURURL, config.Runtime.CompletionPath, config.CompletionInterval, false)
}()

err = downloadPkgbuildsSources(do.Aur, incompatible)
if err != nil {
Expand Down
Loading

0 comments on commit f3925e2

Please sign in to comment.