浏览代码

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

Fixes #1027
Jguer 5 年之前
父节点
当前提交
d34a84204a
共有 2 个文件被更改,包括 36 次插入5 次删除
  1. 34 5
      download.go
  2. 2 0
      go.mod

+ 34 - 5
download.go

@@ -60,6 +60,33 @@ func gitHasDiff(path string, name string) (bool, error) {
 	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) {
 	_, err := os.Stat(filepath.Join(path, name, ".git"))
 	if os.IsNotExist(err) {
@@ -236,11 +263,13 @@ func getPkgbuildsfromABS(pkgs []string, path string) (bool, error) {
 			name = pkg.Name()
 		}
 
+		// TODO: Check existence with ls-remote
+		// https://git.archlinux.org/svntogit/packages.git
 		switch pkg.DB().Name() {
 		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":
-			url = "https://git.archlinux.org/svntogit/community.git/snapshot/packages/" + name + ".tar.gz"
+			url = "https://git.archlinux.org/svntogit/community.git"
 		default:
 			missing = append(missing, name)
 			continue
@@ -270,16 +299,16 @@ func getPkgbuildsfromABS(pkgs []string, path string) (bool, error) {
 
 	download := func(pkg string, url string) {
 		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()))))
 			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()
 		downloaded++
 		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 {
 			fmt.Printf(bold(cyan("::"))+" Downloaded PKGBUILD from ABS (%d/%d): %s\n", downloaded, len(names), cyan(pkg))
 		}

+ 2 - 0
go.mod

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