Forráskód Böngészése

Save the VSC info when install finishes.

Save the VSC Info as soon as the package install finishes. This should
ensure the VSC db does not end up in an incorrect state if an install
fails or is cancelled by the user.

This also adds better support for split packages. When one or more
packages are installed from the same base each individual package is
added to the db not just the base. This allows us to track individual
updates from the same base so that if one package gets updated we don't
assume all packages in the base are updated.
morganamilo 7 éve
szülő
commit
8fb83f3e70
4 módosított fájl, 17 hozzáadás és 25 törlés
  1. 0 11
      cmd.go
  2. 0 3
      config.go
  3. 10 10
      install.go
  4. 7 1
      vcs.go

+ 0 - 11
cmd.go

@@ -127,8 +127,6 @@ func initYay() (err error) {
 	/////////////////
 	// vcs config //
 	////////////////
-	updated = false
-
 	vfile, err := os.OpenFile(vcsFile, os.O_RDONLY|os.O_CREATE, 0644)
 	if err == nil {
 		defer vfile.Close()
@@ -237,15 +235,6 @@ cleanup:
 	//if we fail to save the configuration
 	//at least continue on and try clean up other parts
 
-	if updated {
-		err = saveVCSInfo()
-
-		if err != nil {
-			fmt.Println(err)
-			status = 1
-		}
-	}
-
 	if changedConfig {
 		err = config.saveConfig()
 

+ 0 - 3
config.go

@@ -57,9 +57,6 @@ var vcsFile string
 //completion file
 var completionFile string
 
-// Updated returns if database has been updated
-var updated bool
-
 // changedConfig holds whether or not the config has changed
 var changedConfig bool
 

+ 10 - 10
install.go

@@ -314,13 +314,15 @@ func askEditPkgBuilds(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg) error {
 	return nil
 }
 
-func updateVSCdb(pkgbuild *gopkg.PKGBUILD) {
+func updateVSCdb(pkgs []*rpc.Pkg, pkgbuild *gopkg.PKGBUILD) {
 	for _, pkgsource := range pkgbuild.Source {
 		owner, repo := parseSource(pkgsource)
 		if owner != "" && repo != "" {
-			err := branchInfo(pkgbuild.Pkgbase, owner, repo)
-			if err != nil {
-				fmt.Println(err)
+			for _, pkg := range pkgs {
+				err := branchInfo(pkg.Name, owner, repo)
+				if err != nil {
+					fmt.Println(err)
+				}
 			}
 		}
 	}
@@ -339,7 +341,7 @@ func parsesrcinfosFile(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD, bas
 		}
 
 		srcinfos[pkg.PackageBase] = pkgbuild
-		updateVSCdb(pkgbuild)
+		updateVSCdb(bases[pkg.PackageBase], pkgbuild)
 	}
 
 	return nil
@@ -367,7 +369,6 @@ func parsesrcinfosGenerate(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD,
 		}
 
 		srcinfos[pkg.PackageBase] = pkgbuild
-		updateVSCdb(pkgbuild)
 	}
 
 	return nil
@@ -402,10 +403,7 @@ func downloadPkgBuildsSources(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg) (err
 }
 
 func buildInstallPkgBuilds(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD, targets stringSet, parser *arguments, bases map[string][]*rpc.Pkg) error {
-	//for n := len(pkgs) -1 ; n > 0; n-- {
-	for n := 0; n < len(pkgs); n++ {
-		pkg := pkgs[n]
-
+	for _, pkg := range pkgs {
 		dir := config.BuildDir + pkg.PackageBase + "/"
 		built := true
 
@@ -469,6 +467,8 @@ func buildInstallPkgBuilds(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD,
 		if err != nil {
 			return err
 		}
+
+		updateVSCdb(bases[pkg.PackageBase], srcinfo)
 		if len(depArguments.targets) > 0 {
 			err = passToPacman(depArguments)
 			if err != nil {

+ 7 - 1
vcs.go

@@ -129,7 +129,7 @@ func inStore(pkgName string) *Info {
 
 // branchInfo updates saved information
 func branchInfo(pkgName string, owner string, repoName string) (err error) {
-	updated = true
+	updated := false
 	var newRepo repo
 	var newBranches branches
 	url := "https://api.github.com/repos/" + owner + "/" + repoName
@@ -155,6 +155,8 @@ func branchInfo(pkgName string, owner string, repoName string) (err error) {
 
 	for _, e := range newBranches {
 		if e.Name == defaultBranch {
+			updated = true
+
 			if packinfo != nil {
 				packinfo.Package = pkgName
 				packinfo.URL = url
@@ -165,6 +167,10 @@ func branchInfo(pkgName string, owner string, repoName string) (err error) {
 		}
 	}
 
+	if updated {
+		saveVCSInfo()
+	}
+
 	return
 }