Separate gendb from install

This commit is contained in:
morganamilo 2018-03-22 18:23:20 +00:00
parent 074ea4465a
commit 1e01eafb43
No known key found for this signature in database
GPG key ID: 6FE9E7996B0B082E
4 changed files with 51 additions and 34 deletions

3
cmd.go
View file

@ -288,9 +288,6 @@ func handleYay() (err error) {
usage() usage()
} else if cmdArgs.existsArg("gendb") { } else if cmdArgs.existsArg("gendb") {
err = createDevelDB() err = createDevelDB()
if err != nil {
return
}
} else if cmdArgs.existsArg("c", "clean") { } else if cmdArgs.existsArg("c", "clean") {
err = cleanDependencies() err = cleanDependencies()
} else if len(cmdArgs.targets) > 0 { } else if len(cmdArgs.targets) > 0 {

View file

@ -70,6 +70,20 @@ func splitDbFromName(pkg string) (string, string) {
return "", split[0] return "", split[0]
} }
func getBases(pkgs map[string]*rpc.Pkg) map[string][]*rpc.Pkg {
bases := make(map[string][]*rpc.Pkg)
for _, pkg := range pkgs {
_, ok := bases[pkg.PackageBase]
if !ok {
bases[pkg.PackageBase] = make([]*rpc.Pkg, 0)
}
bases[pkg.PackageBase] = append(bases[pkg.PackageBase], pkg)
}
return bases
}
// Step two of dependency resolving. We already have all the information on the // Step two of dependency resolving. We already have all the information on the
// packages we need, now it's just about ordering them correctly. // packages we need, now it's just about ordering them correctly.
// pkgs is a list of targets, the packages we want to install. Dependencies are // pkgs is a list of targets, the packages we want to install. Dependencies are
@ -105,13 +119,7 @@ func getDepCatagories(pkgs []string, dt *depTree) (*depCatagories, error) {
dc := makeDependCatagories() dc := makeDependCatagories()
seen := make(stringSet) seen := make(stringSet)
for _, pkg := range dt.Aur { dc.Bases = getBases(dt.Aur)
_, ok := dc.Bases[pkg.PackageBase]
if !ok {
dc.Bases[pkg.PackageBase] = make([]*rpc.Pkg, 0)
}
dc.Bases[pkg.PackageBase] = append(dc.Bases[pkg.PackageBase], pkg)
}
for _, pkg := range pkgs { for _, pkg := range pkgs {
_, name := splitDbFromName(pkg) _, name := splitDbFromName(pkg)

View file

@ -125,12 +125,10 @@ func install(parser *arguments) error {
hasAur = len(dc.Aur) != 0 hasAur = len(dc.Aur) != 0
fmt.Println() fmt.Println()
if !parser.existsArg("gendb") {
err = checkForAllConflicts(dc) err = checkForAllConflicts(dc)
if err != nil { if err != nil {
return err return err
} }
}
if len(dc.MakeOnly) > 0 { if len(dc.MakeOnly) > 0 {
if !continueTask("Remove make dependencies after install?", "yY") { if !continueTask("Remove make dependencies after install?", "yY") {
@ -162,19 +160,6 @@ func install(parser *arguments) error {
return err return err
} }
if arguments.existsArg("gendb") {
for _, pkg := range dc.Aur {
pkgbuild := srcinfosStale[pkg.PackageBase]
for _, pkg := range dc.Bases[pkg.PackageBase] {
updateVCSData(pkg.Name, pkgbuild.Source)
}
}
fmt.Println(bold(green(arrow + " GenDB finished. No packages were installed")))
return nil
}
incompatable, err = getIncompatable(dc.Aur, srcinfosStale, dc.Bases) incompatable, err = getIncompatable(dc.Aur, srcinfosStale, dc.Bases)
if err != nil { if err != nil {
return err return err
@ -186,7 +171,7 @@ func install(parser *arguments) error {
} }
} }
if !parser.existsArg("gendb") && (len(arguments.targets) > 0 || arguments.existsArg("u")) { if len(arguments.targets) > 0 || arguments.existsArg("u") {
err := passToPacman(arguments) err := passToPacman(arguments)
if err != nil { if err != nil {
return fmt.Errorf("Error installing repo packages") return fmt.Errorf("Error installing repo packages")

37
vcs.go
View file

@ -3,10 +3,14 @@ package main
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
"time" "time"
rpc "github.com/mikkeloscar/aur"
gopkg "github.com/mikkeloscar/gopkgbuild"
) )
// Info contains the last commit sha of a repo // Info contains the last commit sha of a repo
@ -20,16 +24,39 @@ type shaInfo struct {
// 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 {
infoMap := make(map[string]*rpc.Pkg)
srcinfosStale := make(map[string]*gopkg.PKGBUILD)
_, _, _, remoteNames, err := filterPackages() _, _, _, remoteNames, err := filterPackages()
if err != nil { if err != nil {
return err return err
} }
config.NoConfirm = true info, err := aurInfo(remoteNames)
arguments := makeArguments() if err != nil {
arguments.addArg("gendb") return err
arguments.addTarget(remoteNames...) }
err = install(arguments)
for _, pkg := range info {
infoMap[pkg.Name] = pkg
}
bases := getBases(infoMap)
downloadPkgBuilds(info, sliceToStringSet(remoteNames), bases)
err = parsesrcinfosFile(info, srcinfosStale, bases)
for _, pkg := range info {
pkgbuild := srcinfosStale[pkg.PackageBase]
for _, pkg := range bases[pkg.PackageBase] {
updateVCSData(pkg.Name, pkgbuild.Source)
}
}
fmt.Println(bold(green(arrow + " GenDB finished. No packages were installed")))
return err return err
} }