Parallel AUR Update list

This commit is contained in:
Jguer 2017-07-12 19:54:29 +01:00
parent 73f8c32176
commit 464cf208c1
3 changed files with 125 additions and 4 deletions

View file

@ -31,14 +31,28 @@ func install(pkgs []string, flags []string) error {
// Upgrade handles updating the cache and installing updates.
func upgrade(flags []string) error {
errp := config.PassToPacman("-Syu", nil, flags)
erra := aur.Upgrade(flags)
errp := config.PassToPacman("-Sy", nil, flags)
if errp != nil {
return errp
}
return erra
aurUpList, err := aur.UpgradeList(flags)
if err != nil {
return err
}
fmt.Printf("%+v\n", aurUpList)
// erra := aur.Upgrade(flags)
// if errp != nil {
// return errp
// }
// var buffer bytes.Buffer
// buffer.WriteString("\n")
// fmt.Println("\x1b[1;36;1m::\x1b[0m\x1b[1m Starting AUR upgrade...\x1b[0m")
// return erra
return nil
}
// CleanDependencies removels all dangling dependencies in system

View file

@ -132,6 +132,78 @@ func develUpgrade(foreign map[string]alpm.Package, flags []string) error {
return nil
}
type upgrade struct {
Name string
LocalVersion string
RemoteVersion string
}
func UpgradeList(flags []string) (toUpgrade []upgrade, err error) {
foreign, foreignNames, err := pacman.ForeignPackageList()
if err != nil {
return
}
var qtemp Query
var j int
var routines int
var routineDone int
packageC := make(chan upgrade, 8)
done := make(chan bool)
for i := len(foreign); i != 0; i = j {
j = i - config.YayConf.RequestSplitN
if j < 0 {
j = 0
}
qtemp, err = rpc.Info(foreignNames[j:i])
if err != nil {
return
}
routines++
go func(qtemp Query, local []alpm.Package) {
// For each item in query: Search equivalent in foreign.
// We assume they're ordered and are returned ordered
// and will only be missing if they don't exist in AUR.
max := len(qtemp) - 1
var missing, x int
fmt.Print("\n")
for i, _ := range local {
x = i - missing
if x > max {
break
} else if qtemp[x].Name == local[i].Name() {
if (config.YayConf.TimeUpdate && (int64(qtemp[x].LastModified) > local[i].BuildDate().Unix())) ||
(alpm.VerCmp(local[i].Version(), qtemp[x].Version) < 0) {
packageC <- upgrade{qtemp[x].Name, local[i].Version(), qtemp[x].Version}
continue
}
} else {
missing++
}
}
done <- true
}(qtemp, foreign[j:i])
}
for {
select {
case pkg := <-packageC:
toUpgrade = append(toUpgrade, pkg)
case <-done:
routineDone++
if routineDone == routines {
err = nil
return
}
}
}
}
// Upgrade tries to update every foreign package installed in the system
func Upgrade(flags []string) error {
fmt.Println("\x1b[1;36;1m::\x1b[0m\x1b[1m Starting AUR upgrade...\x1b[0m")

View file

@ -256,6 +256,41 @@ func ForeignPackages() (foreign map[string]alpm.Package, err error) {
return
}
// ForeignPackages returns a map of foreign packages, with their version and date as values.
func ForeignPackageList() (packages []alpm.Package, packageNames []string, err error) {
localDb, err := config.AlpmHandle.LocalDb()
if err != nil {
return
}
dbList, err := config.AlpmHandle.SyncDbs()
if err != nil {
return
}
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 {
packages = append(packages, k)
packageNames = append(packageNames, k.Name())
}
return nil
}
err = localDb.PkgCache().ForEach(f)
return
}
// Statistics returns statistics about packages installed in system
func Statistics() (info struct {
Totaln int