ソースを参照

First version of fully working vcs updates

Jguer 8 年 前
コミット
fd6b2be76b
5 ファイル変更87 行追加34 行削除
  1. 7 0
      README.md
  2. 27 17
      aur/aur.go
  3. 23 12
      aur/result.go
  4. 27 5
      aur/vcs/github.go
  5. 3 0
      yay.go

+ 7 - 0
README.md

@@ -36,6 +36,13 @@ Yay was created with a few objectives in mind and based on the design of yaourt
 
 ### Changelog
 
+#### 2.
+- Fetching backend changed to Mikkel Oscar's [Aur](https://github.com/mikkeloscar/aur)
+- Added support for development packages from github.
+- Pacman backend rewritten and simplified
+- Added config framework.
+
+
 #### 1.115
 - Added AUR completions (updates on first completion every 48h)
 

+ 27 - 17
aur/aur.go

@@ -8,6 +8,7 @@ import (
 	"sort"
 	"strings"
 
+	alpm "github.com/jguer/go-alpm"
 	vcs "github.com/jguer/yay/aur/vcs"
 	"github.com/jguer/yay/config"
 	"github.com/jguer/yay/pacman"
@@ -109,29 +110,31 @@ func CreateDevelDB() error {
 	return err
 }
 
-func DevelUpgrade(flags []string) {
+func develUpgrade(foreign map[string]alpm.Package, flags []string) error {
+	fmt.Println(" Checking development packages...")
+	develUpdates := vcs.CheckUpdates(foreign)
+	if len(develUpdates) != 0 {
+		for _, q := range develUpdates {
+			fmt.Printf("\x1b[1m\x1b[32m==>\x1b[33;1m %s\x1b[0m\n", q)
+		}
+		// Install updated packages
+		if !config.ContinueTask("Proceed with upgrade?", "nN") {
+			return nil
+		}
+
+		err := Install(develUpdates, flags)
+		if err != nil {
+			fmt.Println(err)
+		}
+	}
 
+	return nil
 }
+
 // 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")
 
-	if config.YayConf.Devel {
-		fmt.Println(" Checking development packages...")
-		develUpdates := vcs.CheckUpdates()
-		if len(develUpdates) != 0 {
-			// Install updated packages
-			if !config.ContinueTask("\nProceed with upgrade?", "nN") {
-				return nil
-			}
-
-			err := Install(develUpdates, flags)
-			if err != nil {
-				fmt.Println(err)
-			}
-		}
-	}
-
 	foreign, err := pacman.ForeignPackages()
 	if err != nil {
 		return err
@@ -143,6 +146,13 @@ func Upgrade(flags []string) error {
 		i++
 	}
 
+	if config.YayConf.Devel {
+		err := develUpgrade(foreign, flags)
+		if err != nil {
+			fmt.Println(err)
+		}
+	}
+
 	q, err := rpc.Info(keys)
 	if err != nil {
 		return err

+ 23 - 12
aur/result.go

@@ -66,12 +66,7 @@ func printDeps(repoDeps []string, aurDeps []string) {
 	}
 }
 
-// PkgInstall handles install from Info Result.
-func PkgInstall(a *rpc.Pkg, flags []string) (finalmdeps []string, err error) {
-	fmt.Printf("\x1b[1;32m==> Installing\x1b[33m %s\x1b[0m\n", a.Name)
-	if a.Maintainer == "" {
-		fmt.Println("\x1b[1;31;40m==> Warning:\x1b[0;;40m This package is orphaned.\x1b[0m")
-	}
+func setupPackageSpace(a *rpc.Pkg) (err error) {
 	dir := config.YayConf.BuildDir + a.PackageBase + "/"
 
 	if _, err = os.Stat(dir); !os.IsNotExist(err) {
@@ -99,11 +94,29 @@ func PkgInstall(a *rpc.Pkg, flags []string) (finalmdeps []string, err error) {
 				if err != nil {
 					fmt.Println(err)
 				}
-				vcs.SaveBranchInfo()
 			}
 		}
 	}
 
+	err = os.Chdir(dir)
+	if err != nil {
+		return
+	}
+
+	return
+}
+
+// PkgInstall handles install from Info Result.
+func PkgInstall(a *rpc.Pkg, flags []string) (finalmdeps []string, err error) {
+	fmt.Printf("\x1b[1;32m==> Installing\x1b[33m %s\x1b[0m\n", a.Name)
+	if a.Maintainer == "" {
+		fmt.Println("\x1b[1;31;40m==> Warning:\x1b[0;;40m This package is orphaned.\x1b[0m")
+	}
+
+	if err = setupPackageSpace(a); err != nil {
+		return
+	}
+
 	if specialDBsauce {
 		return
 	}
@@ -158,16 +171,14 @@ func PkgInstall(a *rpc.Pkg, flags []string) (finalmdeps []string, err error) {
 		}
 	}
 
-	err = os.Chdir(dir)
-	if err != nil {
-		return
-	}
-
 	args := []string{"-sri"}
 	args = append(args, flags...)
 	makepkgcmd := exec.Command(config.YayConf.MakepkgBin, args...)
 	makepkgcmd.Stdin, makepkgcmd.Stdout, makepkgcmd.Stderr = os.Stdin, os.Stdout, os.Stderr
 	err = makepkgcmd.Run()
+	if err == nil {
+		_ = vcs.SaveBranchInfo()
+	}
 	return
 }
 

+ 27 - 5
aur/vcs/github.go

@@ -6,6 +6,8 @@ import (
 	"net/http"
 	"os"
 	"strings"
+
+	alpm "github.com/jguer/go-alpm"
 )
 
 // branch contains the information of a repository branch
@@ -103,10 +105,15 @@ func (info *Info) needsUpdate() bool {
 	return false
 }
 
-func CheckUpdates() (toUpdate []string) {
+// CheckUpdates returns list of outdated packages
+func CheckUpdates(foreign map[string]alpm.Package) (toUpdate []string) {
 	for _, e := range savedInfo {
 		if e.needsUpdate() {
-			toUpdate = append(toUpdate, e.Package)
+			if _, ok := foreign[e.Package]; ok {
+				toUpdate = append(toUpdate, e.Package)
+			} else {
+				RemovePackage([]string{e.Package})
+			}
 		}
 	}
 	return
@@ -121,8 +128,23 @@ func inStore(url string) *Info {
 	return nil
 }
 
+// RemovePackage removes package from VCS information
+func RemovePackage(pkgs []string) {
+	for _, pkgName := range pkgs {
+		for i, e := range savedInfo {
+			if e.Package == pkgName {
+				savedInfo[i] = savedInfo[len(savedInfo)-1]
+				savedInfo = savedInfo[:len(savedInfo)-1]
+			}
+		}
+	}
+
+	_ = SaveBranchInfo()
+	return
+}
+
 // BranchInfo updates saved information
-func BranchInfo(pkgname string, owner string, repo string) (err error) {
+func BranchInfo(pkgName string, owner string, repo string) (err error) {
 	Updated = true
 	var newRepo branches
 	url := "https://api.github.com/repos/" + owner + "/" + repo + "/branches"
@@ -139,11 +161,11 @@ func BranchInfo(pkgname string, owner string, repo string) (err error) {
 	for _, e := range newRepo {
 		if e.Name == "master" {
 			if packinfo != nil {
-				packinfo.Package = pkgname
+				packinfo.Package = pkgName
 				packinfo.URL = url
 				packinfo.SHA = e.Commit.SHA
 			} else {
-				savedInfo = append(savedInfo, Info{Package: pkgname, URL: url, SHA: e.Commit.SHA})
+				savedInfo = append(savedInfo, Info{Package: pkgName, URL: url, SHA: e.Commit.SHA})
 			}
 		}
 	}

+ 3 - 0
yay.go

@@ -137,6 +137,9 @@ func main() {
 			err = numberMenu(pkgs, options)
 		}
 	default:
+		if op[0] == 'R' {
+			vcs.RemovePackage(pkgs)
+		}
 		err = config.PassToPacman(op, pkgs, options)
 	}