From 8fb83f3e70713552ed6d261d37989ec5d8b3c482 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Tue, 27 Feb 2018 12:06:30 +0000 Subject: [PATCH] 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. --- cmd.go | 11 ----------- config.go | 3 --- install.go | 20 ++++++++++---------- vcs.go | 8 +++++++- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/cmd.go b/cmd.go index c7a6dadd..6ac35463 100644 --- a/cmd.go +++ b/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() diff --git a/config.go b/config.go index e5ae6fe4..da5c6f63 100644 --- a/config.go +++ b/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 diff --git a/install.go b/install.go index 8fbf2eb9..e26f3110 100644 --- a/install.go +++ b/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 { diff --git a/vcs.go b/vcs.go index 2f6ef37b..5403fbb4 100644 --- a/vcs.go +++ b/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 }