From 8fa7c4069e520152aec7cb0c69432a94424b524c Mon Sep 17 00:00:00 2001 From: Jguer Date: Wed, 18 Oct 2017 11:38:19 +0900 Subject: [PATCH] Resolves #57. Added Package ignoring to AUR. Handles made private. --- cmd.go | 6 +++--- completions.go | 2 +- config.go | 4 ++-- dependencies.go | 8 ++++---- download.go | 2 +- print.go | 6 +++--- query.go | 14 +++++++------- upgrade.go | 47 ++++++++++++++++++++++++++++------------------- 8 files changed, 49 insertions(+), 40 deletions(-) diff --git a/cmd.go b/cmd.go index 35354461..9a764368 100644 --- a/cmd.go +++ b/cmd.go @@ -75,13 +75,13 @@ func init() { } } - AlpmConf, err = readAlpmConfig(config.PacmanConf) + alpmConf, err = readAlpmConfig(config.PacmanConf) if err != nil { fmt.Println("Unable to read Pacman conf", err) os.Exit(1) } - AlpmHandle, err = AlpmConf.CreateHandle() + alpmHandle, err = alpmConf.CreateHandle() if err != nil { fmt.Println("Unable to CreateHandle", err) os.Exit(1) @@ -253,7 +253,7 @@ func main() { } - erra = AlpmHandle.Release() + erra = alpmHandle.Release() if erra != nil { fmt.Println(err) } diff --git a/completions.go b/completions.go index ccf83bfd..aaba92cd 100644 --- a/completions.go +++ b/completions.go @@ -37,7 +37,7 @@ func createAURList(out *os.File) (err error) { //CreatePackageList appends Repo packages to completion cache func createRepoList(out *os.File) (err error) { - dbList, err := AlpmHandle.SyncDbs() + dbList, err := alpmHandle.SyncDbs() if err != nil { return } diff --git a/config.go b/config.go index 546d32a7..cf8cb87a 100644 --- a/config.go +++ b/config.go @@ -59,10 +59,10 @@ var updated bool var config Configuration // AlpmConf holds the current config values for pacman. -var AlpmConf alpm.PacmanConfig +var alpmConf alpm.PacmanConfig // AlpmHandle is the alpm handle used by yay. -var AlpmHandle *alpm.Handle +var alpmHandle *alpm.Handle func readAlpmConfig(pacmanconf string) (conf alpm.PacmanConfig, err error) { file, err := os.Open(pacmanconf) diff --git a/dependencies.go b/dependencies.go index d87057fc..5c364e06 100644 --- a/dependencies.go +++ b/dependencies.go @@ -10,12 +10,12 @@ import ( // BuildDependencies finds packages, on the second run // compares with a baselist and avoids searching those func buildDependencies(baselist []string) func(toCheck []string, isBaseList bool, last bool) (repo []string, notFound []string) { - localDb, err := AlpmHandle.LocalDb() + localDb, err := alpmHandle.LocalDb() if err != nil { panic(err) } - dbList, err := AlpmHandle.SyncDbs() + dbList, err := alpmHandle.SyncDbs() if err != nil { panic(err) } @@ -54,11 +54,11 @@ func buildDependencies(baselist []string) func(toCheck []string, isBaseList bool // DepSatisfier receives a string slice, returns a slice of packages found in // repos and one of packages not found in repos. Leaves out installed packages. func depSatisfier(toCheck []string) (repo []string, notFound []string, err error) { - localDb, err := AlpmHandle.LocalDb() + localDb, err := alpmHandle.LocalDb() if err != nil { return } - dbList, err := AlpmHandle.SyncDbs() + dbList, err := alpmHandle.SyncDbs() if err != nil { return } diff --git a/download.go b/download.go index 7bef5749..7ade9bc8 100644 --- a/download.go +++ b/download.go @@ -81,7 +81,7 @@ func getPkgbuild(pkg string) (err error) { // GetPkgbuild downloads pkgbuild from the ABS. func getPkgbuildfromABS(pkgN string, path string) (err error) { - dbList, err := AlpmHandle.SyncDbs() + dbList, err := alpmHandle.SyncDbs() if err != nil { return } diff --git a/print.go b/print.go index fddb7012..1ee81962 100644 --- a/print.go +++ b/print.go @@ -21,7 +21,7 @@ func human(size int64) string { // PrintSearch handles printing search results in a given format func (q aurQuery) printSearch(start int) { - localDb, _ := AlpmHandle.LocalDb() + localDb, _ := alpmHandle.LocalDb() for i, res := range q { var toprint string @@ -75,7 +75,7 @@ func (s repoQuery) printSearch() { toprint += fmt.Sprint(res.Groups().Slice(), " ") } - localDb, err := AlpmHandle.LocalDb() + localDb, err := alpmHandle.LocalDb() if err == nil { if _, err = localDb.PkgByName(res.Name()); err == nil { toprint += fmt.Sprintf("\x1b[32;40mInstalled\x1b[0m") @@ -163,7 +163,7 @@ func PrintInfo(a *rpc.Pkg) { // BiggestPackages prints the name of the ten biggest packages in the system. func biggestPackages() { - localDb, err := AlpmHandle.LocalDb() + localDb, err := alpmHandle.LocalDb() if err != nil { return } diff --git a/query.go b/query.go index dad3fd35..3e2adc3e 100644 --- a/query.go +++ b/query.go @@ -33,11 +33,11 @@ func (q aurQuery) Swap(i, j int) { // FilterPackages filters packages based on source and type from local repository. func filterPackages() (local []alpm.Package, remote []alpm.Package, localNames []string, remoteNames []string, err error) { - localDb, err := AlpmHandle.LocalDb() + localDb, err := alpmHandle.LocalDb() if err != nil { return } - dbList, err := AlpmHandle.SyncDbs() + dbList, err := alpmHandle.SyncDbs() if err != nil { return } @@ -249,7 +249,7 @@ func localStatistics(version string) error { // Search handles repo searches. Creates a RepoSearch struct. func queryRepo(pkgInputN []string) (s repoQuery, n int, err error) { - dbList, err := AlpmHandle.SyncDbs() + dbList, err := alpmHandle.SyncDbs() if err != nil { return } @@ -299,7 +299,7 @@ func queryRepo(pkgInputN []string) (s repoQuery, n int, err error) { // PackageSlices separates an input slice into aur and repo slices func packageSlices(toCheck []string) (aur []string, repo []string, err error) { - dbList, err := AlpmHandle.SyncDbs() + dbList, err := alpmHandle.SyncDbs() if err != nil { return } @@ -336,7 +336,7 @@ func packageSlices(toCheck []string) (aur []string, repo []string, err error) { // HangingPackages returns a list of packages installed as deps // and unneeded by the system func hangingPackages() (hanging []string, err error) { - localDb, err := AlpmHandle.LocalDb() + localDb, err := alpmHandle.LocalDb() if err != nil { return } @@ -368,7 +368,7 @@ func statistics() (info struct { var nPkg int var ePkg int - localDb, err := AlpmHandle.LocalDb() + localDb, err := alpmHandle.LocalDb() if err != nil { return } @@ -395,7 +395,7 @@ func statistics() (info struct { // SliceHangingPackages returns a list of packages installed as deps // and unneeded by the system from a provided list of package names. func sliceHangingPackages(pkgS []string) (hanging []string) { - localDb, err := AlpmHandle.LocalDb() + localDb, err := alpmHandle.LocalDb() if err != nil { return } diff --git a/upgrade.go b/upgrade.go index 25baa272..dadf4ca4 100644 --- a/upgrade.go +++ b/upgrade.go @@ -141,6 +141,26 @@ loop: return } +func isIgnored(pkg alpm.Package) bool { + for _, p := range alpmConf.IgnorePkg { + if p == pkg.Name() { + fmt.Printf("\x1b[33mwarning:\x1b[0m %s (ignored pkg) ignoring upgrade (%s)\n", pkg.Name(), pkg.Version()) + return true + } + } + + for _, g := range alpmConf.IgnoreGroup { + for _, pg := range pkg.Groups().Slice() { + if g == pg { + fmt.Printf("\x1b[33mwarning:\x1b[0m %s (ignored pkg) ignoring upgrade (%s)\n", pkg.Name(), pkg.Version()) + return true + } + } + + } + return false +} + // upAUR gathers foreign packages and checks if they have new versions. // Output: Upgrade type package list. func upAUR(remote []alpm.Package, remoteNames []string) (toUpgrade upSlice, err error) { @@ -173,6 +193,9 @@ func upAUR(remote []alpm.Package, remoteNames []string) (toUpgrade upSlice, err var missing, x int for i := range local { + if isIgnored(local[i]) { + continue + } x = i - missing if x > max { break @@ -207,34 +230,20 @@ func upAUR(remote []alpm.Package, remoteNames []string) (toUpgrade upSlice, err // upRepo gathers local packages and checks if they have new versions. // Output: Upgrade type package list. func upRepo(local []alpm.Package) (upSlice, error) { - dbList, err := AlpmHandle.SyncDbs() + dbList, err := alpmHandle.SyncDbs() if err != nil { return nil, err } slice := upSlice{} -primeloop: + for _, pkg := range local { + if isIgnored(pkg) { + continue + } newPkg := pkg.NewVersion(dbList) if newPkg != nil { - for _, ignorePkg := range AlpmConf.IgnorePkg { - if pkg.Name() == ignorePkg { - fmt.Printf("\x1b[33mwarning:\x1b[0m %s (ignored pkg) ignoring upgrade (%s -> %s)\n", pkg.Name(), pkg.Version(), newPkg.Version()) - continue primeloop - } - } - - for _, ignoreGroup := range AlpmConf.IgnoreGroup { - for _, group := range pkg.Groups().Slice() { - if group == ignoreGroup { - fmt.Printf("\x1b[33mwarning:\x1b[0m %s (ignored group) ignoring upgrade (%s -> %s)\n", pkg.Name(), pkg.Version(), newPkg.Version()) - continue primeloop - - } - } - } - slice = append(slice, upgrade{pkg.Name(), newPkg.DB().Name(), pkg.Version(), newPkg.Version()}) } }