Changes -G in ABS to use git and symlink result.

Fixes #1027
This commit is contained in:
Jguer 2019-09-20 18:18:53 +01:00 committed by J Guerreiro
parent 1901138e4c
commit d34a84204a
2 changed files with 36 additions and 5 deletions

View File

@ -60,6 +60,33 @@ func gitHasDiff(path string, name string) (bool, error) {
return head != upstream, nil return head != upstream, nil
} }
// TODO: yay-next passes args through the header, use that to unify ABS and AUR
func gitDownloadABS(url string, path string, name string) (bool, error) {
_, err := os.Stat(filepath.Join(path, name))
if os.IsNotExist(err) {
cmd := passToGit(path, "clone", "--no-progress", "--single-branch",
"-b", "packages/"+name, url, name)
cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0")
_, stderr, err := capture(cmd)
if err != nil {
return false, fmt.Errorf("error cloning %s: %s", name, stderr)
}
return true, nil
} else if err != nil {
return false, fmt.Errorf("error reading %s", filepath.Join(path, name, ".git"))
}
cmd := passToGit(filepath.Join(path, name), "fetch")
cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0")
_, stderr, err := capture(cmd)
if err != nil {
return false, fmt.Errorf("error fetching %s: %s", name, stderr)
}
return true, nil
}
func gitDownload(url string, path string, name string) (bool, error) { func gitDownload(url string, path string, name string) (bool, error) {
_, err := os.Stat(filepath.Join(path, name, ".git")) _, err := os.Stat(filepath.Join(path, name, ".git"))
if os.IsNotExist(err) { if os.IsNotExist(err) {
@ -236,11 +263,13 @@ func getPkgbuildsfromABS(pkgs []string, path string) (bool, error) {
name = pkg.Name() name = pkg.Name()
} }
// TODO: Check existence with ls-remote
// https://git.archlinux.org/svntogit/packages.git
switch pkg.DB().Name() { switch pkg.DB().Name() {
case "core", "extra", "testing": case "core", "extra", "testing":
url = "https://git.archlinux.org/svntogit/packages.git/snapshot/packages/" + name + ".tar.gz" url = "https://git.archlinux.org/svntogit/packages.git"
case "community", "multilib", "community-testing", "multilib-testing": case "community", "multilib", "community-testing", "multilib-testing":
url = "https://git.archlinux.org/svntogit/community.git/snapshot/packages/" + name + ".tar.gz" url = "https://git.archlinux.org/svntogit/community.git"
default: default:
missing = append(missing, name) missing = append(missing, name)
continue continue
@ -270,16 +299,16 @@ func getPkgbuildsfromABS(pkgs []string, path string) (bool, error) {
download := func(pkg string, url string) { download := func(pkg string, url string) {
defer wg.Done() defer wg.Done()
if err := downloadAndUnpack(url, cacheHome); err != nil { if _, err := gitDownloadABS(url, cacheHome, pkg); err != nil {
errs.Add(fmt.Errorf("%s Failed to get pkgbuild: %s: %s", bold(red(arrow)), bold(cyan(pkg)), bold(red(err.Error())))) errs.Add(fmt.Errorf("%s Failed to get pkgbuild: %s: %s", bold(red(arrow)), bold(cyan(pkg)), bold(red(err.Error()))))
return return
} }
_, stderr, err := capture(exec.Command("mv", filepath.Join(cacheHome, "packages", pkg, "trunk"), filepath.Join(path, pkg))) _, stderr, err := capture(exec.Command("ln", "-s", filepath.Join(cacheHome, pkg, "trunk"), filepath.Join(path, pkg)))
mux.Lock() mux.Lock()
downloaded++ downloaded++
if err != nil { if err != nil {
errs.Add(fmt.Errorf("%s Failed to move %s: %s", bold(red(arrow)), bold(cyan(pkg)), bold(red(stderr)))) errs.Add(fmt.Errorf("%s Failed to link %s: %s", bold(red(arrow)), bold(cyan(pkg)), bold(red(stderr))))
} else { } else {
fmt.Printf(bold(cyan("::"))+" Downloaded PKGBUILD from ABS (%d/%d): %s\n", downloaded, len(names), cyan(pkg)) fmt.Printf(bold(cyan("::"))+" Downloaded PKGBUILD from ABS (%d/%d): %s\n", downloaded, len(names), cyan(pkg))
} }

2
go.mod
View File

@ -6,3 +6,5 @@ require (
github.com/Morganamilo/go-srcinfo v1.0.0 github.com/Morganamilo/go-srcinfo v1.0.0
github.com/mikkeloscar/aur v0.0.0-20181111113612-b71516da3ae9 github.com/mikkeloscar/aur v0.0.0-20181111113612-b71516da3ae9
) )
go 1.13