Merge pull request #183 from Morganamilo/fix#88

Save the VSC info when install finishes.
This commit is contained in:
Morgana 2018-02-27 19:08:01 +00:00 committed by GitHub
commit 9c4b4d73f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 25 deletions

11
cmd.go
View file

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

View file

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

View file

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

8
vcs.go
View file

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