mirror of
https://github.com/Jguer/yay.git
synced 2025-11-28 00:05:15 -05:00
FilterPackages replaces ForeignPackages
This commit is contained in:
parent
ef454680dc
commit
9afd66109a
@ -1,6 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
rpc "github.com/mikkeloscar/aur"
|
||||||
|
)
|
||||||
|
|
||||||
// BuildDependencies finds packages, on the second run
|
// BuildDependencies finds packages, on the second run
|
||||||
// compares with a baselist and avoids searching those
|
// compares with a baselist and avoids searching those
|
||||||
@ -76,3 +81,39 @@ func depSatisfier(toCheck []string) (repo []string, notFound []string, err error
|
|||||||
err = nil
|
err = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PkgDependencies returns package dependencies not installed belonging to AUR
|
||||||
|
// 0 is Repo, 1 is Foreign.
|
||||||
|
func pkgDependencies(a *rpc.Pkg) (runDeps [2][]string, makeDeps [2][]string, err error) {
|
||||||
|
var q aurQuery
|
||||||
|
if len(a.Depends) == 0 && len(a.MakeDepends) == 0 {
|
||||||
|
q, err = rpc.Info([]string{a.Name})
|
||||||
|
if len(q) == 0 || err != nil {
|
||||||
|
err = fmt.Errorf("Unable to search dependencies, %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
q = append(q, *a)
|
||||||
|
}
|
||||||
|
|
||||||
|
depSearch := buildDependencies(a.Depends)
|
||||||
|
if len(a.Depends) != 0 {
|
||||||
|
runDeps[0], runDeps[1] = depSearch(q[0].Depends, true, false)
|
||||||
|
if len(runDeps[0]) != 0 || len(runDeps[1]) != 0 {
|
||||||
|
fmt.Println("\x1b[1;32m=>\x1b[1;33m Run Dependencies: \x1b[0m")
|
||||||
|
printDeps(runDeps[0], runDeps[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(a.MakeDepends) != 0 {
|
||||||
|
makeDeps[0], makeDeps[1] = depSearch(q[0].MakeDepends, false, false)
|
||||||
|
if len(makeDeps[0]) != 0 || len(makeDeps[1]) != 0 {
|
||||||
|
fmt.Println("\x1b[1;32m=>\x1b[1;33m Make Dependencies: \x1b[0m")
|
||||||
|
printDeps(makeDeps[0], makeDeps[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
depSearch(a.MakeDepends, false, true)
|
||||||
|
|
||||||
|
err = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
21
install.go
21
install.go
@ -9,6 +9,27 @@ import (
|
|||||||
gopkg "github.com/mikkeloscar/gopkgbuild"
|
gopkg "github.com/mikkeloscar/gopkgbuild"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func newInstall(pkgs []string, flags []string) error {
|
||||||
|
aurs, repos, _ := packageSlices(pkgs)
|
||||||
|
|
||||||
|
if len(repos) != 0 {
|
||||||
|
err := passToPacman("-S", repos, flags)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error installing repo packages.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(aurs) != 0 {
|
||||||
|
err := aurInstall(aurs, flags)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error installing aur packages.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Install handles package installs
|
// Install handles package installs
|
||||||
func install(pkgs []string, flags []string) error {
|
func install(pkgs []string, flags []string) error {
|
||||||
aurs, repos, _ := packageSlices(pkgs)
|
aurs, repos, _ := packageSlices(pkgs)
|
||||||
|
|||||||
128
query.go
128
query.go
@ -30,6 +30,45 @@ func (q aurQuery) Swap(i, j int) {
|
|||||||
q[i], q[j] = q[j], q[i]
|
q[i], q[j] = q[j], q[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dbList, err := AlpmHandle.SyncDbs()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
f := func(k alpm.Package) error {
|
||||||
|
found := false
|
||||||
|
// For each DB search for our secret package.
|
||||||
|
_ = dbList.ForEach(func(d alpm.Db) error {
|
||||||
|
if found {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
_, err := d.PkgByName(k.Name())
|
||||||
|
if err == nil {
|
||||||
|
found = true
|
||||||
|
local = append(local, k)
|
||||||
|
localNames = append(localNames, k.Name())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
remote = append(remote, k)
|
||||||
|
remoteNames = append(remoteNames, k.Name())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err = localDb.PkgCache().ForEach(f)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// MissingPackage warns if the Query was unable to find a package
|
// MissingPackage warns if the Query was unable to find a package
|
||||||
func (q aurQuery) missingPackage(pkgS []string) {
|
func (q aurQuery) missingPackage(pkgS []string) {
|
||||||
for _, depName := range pkgS {
|
for _, depName := range pkgS {
|
||||||
@ -144,7 +183,7 @@ func localStatistics(version string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
foreignS, err := foreignPackages()
|
_, _, _, remoteNames, err := filterPackages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -152,7 +191,7 @@ func localStatistics(version string) error {
|
|||||||
fmt.Printf("\n Yay version r%s\n", version)
|
fmt.Printf("\n Yay version r%s\n", version)
|
||||||
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
||||||
fmt.Printf("\x1B[1;32mTotal installed packages: \x1B[0;33m%d\x1B[0m\n", info.Totaln)
|
fmt.Printf("\x1B[1;32mTotal installed packages: \x1B[0;33m%d\x1B[0m\n", info.Totaln)
|
||||||
fmt.Printf("\x1B[1;32mTotal foreign installed packages: \x1B[0;33m%d\x1B[0m\n", len(foreignS))
|
fmt.Printf("\x1B[1;32mTotal foreign installed packages: \x1B[0;33m%d\x1B[0m\n", len(remoteNames))
|
||||||
fmt.Printf("\x1B[1;32mExplicitly installed packages: \x1B[0;33m%d\x1B[0m\n", info.Expln)
|
fmt.Printf("\x1B[1;32mExplicitly installed packages: \x1B[0;33m%d\x1B[0m\n", info.Expln)
|
||||||
fmt.Printf("\x1B[1;32mTotal Size occupied by packages: \x1B[0;33m%s\x1B[0m\n", human(info.TotalSize))
|
fmt.Printf("\x1B[1;32mTotal Size occupied by packages: \x1B[0;33m%s\x1B[0m\n", human(info.TotalSize))
|
||||||
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
||||||
@ -160,21 +199,14 @@ func localStatistics(version string) error {
|
|||||||
biggestPackages()
|
biggestPackages()
|
||||||
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
fmt.Println("\x1B[1;34m===========================================\x1B[0m")
|
||||||
|
|
||||||
keys := make([]string, len(foreignS))
|
|
||||||
i := 0
|
|
||||||
for k := range foreignS {
|
|
||||||
keys[i] = k
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
|
|
||||||
var q aurQuery
|
var q aurQuery
|
||||||
var j int
|
var j int
|
||||||
for i = len(keys); i != 0; i = j {
|
for i := len(remoteNames); i != 0; i = j {
|
||||||
j = i - config.RequestSplitN
|
j = i - config.RequestSplitN
|
||||||
if j < 0 {
|
if j < 0 {
|
||||||
j = 0
|
j = 0
|
||||||
}
|
}
|
||||||
qtemp, err := rpc.Info(keys[j:i])
|
qtemp, err := rpc.Info(remoteNames[j:i])
|
||||||
q = append(q, qtemp...)
|
q = append(q, qtemp...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -182,7 +214,7 @@ func localStatistics(version string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var outcast []string
|
var outcast []string
|
||||||
for _, s := range keys {
|
for _, s := range remoteNames {
|
||||||
found := false
|
found := false
|
||||||
for _, i := range q {
|
for _, i := range q {
|
||||||
if s == i.Name {
|
if s == i.Name {
|
||||||
@ -265,42 +297,6 @@ func queryRepo(pkgInputN []string) (s repoQuery, n int, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// PkgDependencies returns package dependencies not installed belonging to AUR
|
|
||||||
// 0 is Repo, 1 is Foreign.
|
|
||||||
func pkgDependencies(a *rpc.Pkg) (runDeps [2][]string, makeDeps [2][]string, err error) {
|
|
||||||
var q aurQuery
|
|
||||||
if len(a.Depends) == 0 && len(a.MakeDepends) == 0 {
|
|
||||||
q, err = rpc.Info([]string{a.Name})
|
|
||||||
if len(q) == 0 || err != nil {
|
|
||||||
err = fmt.Errorf("Unable to search dependencies, %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
q = append(q, *a)
|
|
||||||
}
|
|
||||||
|
|
||||||
depSearch := buildDependencies(a.Depends)
|
|
||||||
if len(a.Depends) != 0 {
|
|
||||||
runDeps[0], runDeps[1] = depSearch(q[0].Depends, true, false)
|
|
||||||
if len(runDeps[0]) != 0 || len(runDeps[1]) != 0 {
|
|
||||||
fmt.Println("\x1b[1;32m=>\x1b[1;33m Run Dependencies: \x1b[0m")
|
|
||||||
printDeps(runDeps[0], runDeps[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(a.MakeDepends) != 0 {
|
|
||||||
makeDeps[0], makeDeps[1] = depSearch(q[0].MakeDepends, false, false)
|
|
||||||
if len(makeDeps[0]) != 0 || len(makeDeps[1]) != 0 {
|
|
||||||
fmt.Println("\x1b[1;32m=>\x1b[1;33m Make Dependencies: \x1b[0m")
|
|
||||||
printDeps(makeDeps[0], makeDeps[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
depSearch(a.MakeDepends, false, true)
|
|
||||||
|
|
||||||
err = nil
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// PackageSlices separates an input slice into aur and repo slices
|
// PackageSlices separates an input slice into aur and repo slices
|
||||||
func packageSlices(toCheck []string) (aur []string, repo []string, err error) {
|
func packageSlices(toCheck []string) (aur []string, repo []string, err error) {
|
||||||
dbList, err := AlpmHandle.SyncDbs()
|
dbList, err := AlpmHandle.SyncDbs()
|
||||||
@ -337,42 +333,6 @@ func packageSlices(toCheck []string) (aur []string, repo []string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForeignPackages returns a map of foreign packages, with their version and date as values.
|
|
||||||
func foreignPackages() (foreign map[string]alpm.Package, err error) {
|
|
||||||
localDb, err := AlpmHandle.LocalDb()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
dbList, err := AlpmHandle.SyncDbs()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
foreign = make(map[string]alpm.Package)
|
|
||||||
|
|
||||||
f := func(k alpm.Package) error {
|
|
||||||
found := false
|
|
||||||
_ = dbList.ForEach(func(d alpm.Db) error {
|
|
||||||
if found {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
_, err = d.PkgByName(k.Name())
|
|
||||||
if err == nil {
|
|
||||||
found = true
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
if !found {
|
|
||||||
foreign[k.Name()] = k
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
err = localDb.PkgCache().ForEach(f)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// HangingPackages returns a list of packages installed as deps
|
// HangingPackages returns a list of packages installed as deps
|
||||||
// and unneeded by the system
|
// and unneeded by the system
|
||||||
func hangingPackages() (hanging []string, err error) {
|
func hangingPackages() (hanging []string, err error) {
|
||||||
|
|||||||
41
upgrade.go
41
upgrade.go
@ -57,45 +57,6 @@ func (u upSlice) Less(i, j int) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// FilterPackages filters packages based on source and type.
|
|
||||||
func FilterPackages() (local []alpm.Package, remote []alpm.Package,
|
|
||||||
localNames []string, remoteNames []string, err error) {
|
|
||||||
localDb, err := AlpmHandle.LocalDb()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
dbList, err := AlpmHandle.SyncDbs()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
f := func(k alpm.Package) error {
|
|
||||||
found := false
|
|
||||||
// For each DB search for our secret package.
|
|
||||||
_ = dbList.ForEach(func(d alpm.Db) error {
|
|
||||||
if found {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
_, err := d.PkgByName(k.Name())
|
|
||||||
if err == nil {
|
|
||||||
found = true
|
|
||||||
local = append(local, k)
|
|
||||||
localNames = append(localNames, k.Name())
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
if !found {
|
|
||||||
remote = append(remote, k)
|
|
||||||
remoteNames = append(remoteNames, k.Name())
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
err = localDb.PkgCache().ForEach(f)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print prints the details of the packages to upgrade.
|
// Print prints the details of the packages to upgrade.
|
||||||
func (u upSlice) Print(start int) {
|
func (u upSlice) Print(start int) {
|
||||||
for k, i := range u {
|
for k, i := range u {
|
||||||
@ -133,7 +94,7 @@ func (u upSlice) Print(start int) {
|
|||||||
|
|
||||||
// List returns lists of packages to upgrade from each source.
|
// List returns lists of packages to upgrade from each source.
|
||||||
func upList() (aurUp upSlice, repoUp upSlice, err error) {
|
func upList() (aurUp upSlice, repoUp upSlice, err error) {
|
||||||
local, remote, _, remoteNames, err := FilterPackages()
|
local, remote, _, remoteNames, err := filterPackages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
11
vcs.go
11
vcs.go
@ -32,21 +32,14 @@ type infos []Info
|
|||||||
|
|
||||||
// CreateDevelDB forces yay to create a DB of the existing development packages
|
// CreateDevelDB forces yay to create a DB of the existing development packages
|
||||||
func createDevelDB() error {
|
func createDevelDB() error {
|
||||||
foreign, err := foreignPackages()
|
_, _, _, remoteNames, err := filterPackages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
keys := make([]string, len(foreign))
|
|
||||||
i := 0
|
|
||||||
for k := range foreign {
|
|
||||||
keys[i] = k
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
|
|
||||||
config.NoConfirm = true
|
config.NoConfirm = true
|
||||||
specialDBsauce = true
|
specialDBsauce = true
|
||||||
err = aurInstall(keys, nil)
|
err = aurInstall(remoteNames, nil)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user