|
@@ -6,6 +6,7 @@ import (
|
|
"fmt"
|
|
"fmt"
|
|
"os"
|
|
"os"
|
|
"strings"
|
|
"strings"
|
|
|
|
+ "sync"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
gosrc "github.com/Morganamilo/go-srcinfo"
|
|
gosrc "github.com/Morganamilo/go-srcinfo"
|
|
@@ -23,6 +24,8 @@ 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 {
|
|
|
|
+ var mux sync.Mutex
|
|
|
|
+ var wg sync.WaitGroup
|
|
infoMap := make(map[string]*rpc.Pkg)
|
|
infoMap := make(map[string]*rpc.Pkg)
|
|
srcinfosStale := make(map[string]*gosrc.Srcinfo)
|
|
srcinfosStale := make(map[string]*gosrc.Srcinfo)
|
|
|
|
|
|
@@ -46,29 +49,20 @@ func createDevelDB() error {
|
|
downloadPkgBuilds(info, bases, toSkip)
|
|
downloadPkgBuilds(info, bases, toSkip)
|
|
tryParsesrcinfosFile(info, srcinfosStale, bases)
|
|
tryParsesrcinfosFile(info, srcinfosStale, bases)
|
|
|
|
|
|
- for _, pkg := range info {
|
|
|
|
- pkgbuild, ok := srcinfosStale[pkg.PackageBase]
|
|
|
|
- if !ok {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for _, pkg := range bases[pkg.PackageBase] {
|
|
|
|
- updateVCSData(pkg.Name, pkgbuild.Source)
|
|
|
|
|
|
+ for _, pkgbuild := range srcinfosStale {
|
|
|
|
+ for _, pkg := range pkgbuild.Packages {
|
|
|
|
+ wg.Add(1)
|
|
|
|
+ go updateVCSData(pkg.Pkgname, pkgbuild.Source, &mux, &wg)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ wg.Wait()
|
|
fmt.Println(bold(yellow(arrow) + bold(" GenDB finished. No packages were installed")))
|
|
fmt.Println(bold(yellow(arrow) + bold(" GenDB finished. No packages were installed")))
|
|
-
|
|
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
// parseSource returns the git url, default branch and protocols it supports
|
|
// parseSource returns the git url, default branch and protocols it supports
|
|
func parseSource(source string) (url string, branch string, protocols []string) {
|
|
func parseSource(source string) (url string, branch string, protocols []string) {
|
|
- if !(strings.Contains(source, "git://") ||
|
|
|
|
- strings.Contains(source, ".git") ||
|
|
|
|
- strings.Contains(source, "git+https://")) {
|
|
|
|
- return "", "", nil
|
|
|
|
- }
|
|
|
|
split := strings.Split(source, "::")
|
|
split := strings.Split(source, "::")
|
|
source = split[len(split)-1]
|
|
source = split[len(split)-1]
|
|
split = strings.SplitN(source, "://", 2)
|
|
split = strings.SplitN(source, "://", 2)
|
|
@@ -76,8 +70,20 @@ func parseSource(source string) (url string, branch string, protocols []string)
|
|
if len(split) != 2 {
|
|
if len(split) != 2 {
|
|
return "", "", nil
|
|
return "", "", nil
|
|
}
|
|
}
|
|
-
|
|
|
|
protocols = strings.Split(split[0], "+")
|
|
protocols = strings.Split(split[0], "+")
|
|
|
|
+
|
|
|
|
+ git := false
|
|
|
|
+ for _, protocol := range protocols {
|
|
|
|
+ if protocol == "git" {
|
|
|
|
+ git = true
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if !git {
|
|
|
|
+ return "", "", nil
|
|
|
|
+ }
|
|
|
|
+
|
|
split = strings.SplitN(split[1], "#", 2)
|
|
split = strings.SplitN(split[1], "#", 2)
|
|
if len(split) == 2 {
|
|
if len(split) == 2 {
|
|
secondSplit := strings.SplitN(split[1], "=", 2)
|
|
secondSplit := strings.SplitN(split[1], "=", 2)
|
|
@@ -102,24 +108,29 @@ func parseSource(source string) (url string, branch string, protocols []string)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-func updateVCSData(pkgName string, sources []gosrc.ArchString) {
|
|
|
|
|
|
+func updateVCSData(pkgName string, sources []gosrc.ArchString, mux *sync.Mutex, wg *sync.WaitGroup) {
|
|
|
|
+ defer wg.Done()
|
|
|
|
+
|
|
if savedInfo == nil {
|
|
if savedInfo == nil {
|
|
|
|
+ mux.Lock()
|
|
savedInfo = make(vcsInfo)
|
|
savedInfo = make(vcsInfo)
|
|
|
|
+ mux.Unlock()
|
|
}
|
|
}
|
|
|
|
|
|
info := make(shaInfos)
|
|
info := make(shaInfos)
|
|
-
|
|
|
|
- for _, source := range sources {
|
|
|
|
|
|
+ checkSource := func(source gosrc.ArchString) {
|
|
|
|
+ defer wg.Done()
|
|
url, branch, protocols := parseSource(source.Value)
|
|
url, branch, protocols := parseSource(source.Value)
|
|
if url == "" || branch == "" {
|
|
if url == "" || branch == "" {
|
|
- continue
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
commit := getCommit(url, branch, protocols)
|
|
commit := getCommit(url, branch, protocols)
|
|
if commit == "" {
|
|
if commit == "" {
|
|
- continue
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ mux.Lock()
|
|
info[url] = shaInfo{
|
|
info[url] = shaInfo{
|
|
protocols,
|
|
protocols,
|
|
branch,
|
|
branch,
|
|
@@ -127,9 +138,14 @@ func updateVCSData(pkgName string, sources []gosrc.ArchString) {
|
|
}
|
|
}
|
|
|
|
|
|
savedInfo[pkgName] = info
|
|
savedInfo[pkgName] = info
|
|
-
|
|
|
|
fmt.Println(bold(yellow(arrow)) + " Found git repo: " + cyan(url))
|
|
fmt.Println(bold(yellow(arrow)) + " Found git repo: " + cyan(url))
|
|
saveVCSInfo()
|
|
saveVCSInfo()
|
|
|
|
+ mux.Unlock()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for _, source := range sources {
|
|
|
|
+ wg.Add(1)
|
|
|
|
+ go checkSource(source)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -152,6 +168,7 @@ func getCommit(url string, branch string, protocols []string) string {
|
|
//Introduce a time out so this can not hang
|
|
//Introduce a time out so this can not hang
|
|
timer := time.AfterFunc(5*time.Second, func() {
|
|
timer := time.AfterFunc(5*time.Second, func() {
|
|
cmd.Process.Kill()
|
|
cmd.Process.Kill()
|
|
|
|
+ fmt.Println(bold(yellow(arrow)), "Timeout:", cyan(url))
|
|
})
|
|
})
|
|
|
|
|
|
err = cmd.Wait()
|
|
err = cmd.Wait()
|