aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-05-21 03:38:34 +0700
committerShulhan <ms@kilabit.info>2018-05-21 03:38:34 +0700
commit8f01bf679c2bec9b514f4ea2d0f3d5c4eca9e953 (patch)
treea821f2bfae8afcf6d0d500849473a13288257ea7
parent10ab9cedefd713ad49a62c0b03d73963da21c904 (diff)
downloadbeku-8f01bf679c2bec9b514f4ea2d0f3d5c4eca9e953.tar.xz
Set environment as dirty after sync operation than add or update a package
-rw-r--r--env.go12
-rw-r--r--package.go12
-rw-r--r--package_test.go7
3 files changed, 26 insertions, 5 deletions
diff --git a/env.go b/env.go
index a51224d..8f1816b 100644
--- a/env.go
+++ b/env.go
@@ -529,6 +529,11 @@ func (env *Env) update(curPkg, newPkg *Package) (ok bool, err error) {
}
err = curPkg.Update(newPkg)
+ if err != nil {
+ return
+ }
+
+ env.dirty = true
return
}
@@ -538,10 +543,14 @@ func (env *Env) update(curPkg, newPkg *Package) (ok bool, err error) {
// package and add it as one of package dependencies.
//
func (env *Env) updateMissing(newPkg *Package) {
+ var updated bool
fmt.Println(">>> Update missing ...")
for x := 0; x < len(env.pkgs); x++ {
- env.pkgs[x].UpdateMissingDep(newPkg)
+ updated = env.pkgs[x].UpdateMissingDep(newPkg)
+ if updated {
+ env.dirty = true
+ }
}
var newMissings []string
@@ -613,6 +622,7 @@ func (env *Env) Sync(pkgName, importPath string) (err error) {
if curPkg == nil {
curPkg = newPkg
env.addPackage(newPkg)
+ env.dirty = true
}
err = env.postSync(curPkg, newPkg)
diff --git a/package.go b/package.go
index 0c0550a..4c03efc 100644
--- a/package.go
+++ b/package.go
@@ -467,7 +467,10 @@ func (pkg *Package) Update(newPkg *Package) (err error) {
// (2) add it as one of package dependencies of current package, and,
// (3) add current package as required by new package.
//
-func (pkg *Package) UpdateMissingDep(newPkg *Package) {
+// It will return true if new package solve the missing deps on current
+// package, otherwise it will return false.
+//
+func (pkg *Package) UpdateMissingDep(newPkg *Package) (updated bool) {
var missing []string
for x := 0; x < len(pkg.DepsMissing); x++ {
if !strings.HasPrefix(pkg.DepsMissing[x], newPkg.ImportPath) {
@@ -477,9 +480,14 @@ func (pkg *Package) UpdateMissingDep(newPkg *Package) {
pkg.pushDep(newPkg.ImportPath)
newPkg.pushRequiredBy(pkg.ImportPath)
+ updated = true
+ }
+
+ if updated {
+ pkg.DepsMissing = missing
}
- pkg.DepsMissing = missing
+ return
}
//
diff --git a/package_test.go b/package_test.go
index c82dcc5..993e5a9 100644
--- a/package_test.go
+++ b/package_test.go
@@ -633,6 +633,7 @@ func testUpdateMissingDep(t *testing.T) {
desc string
curPkg *Package
misPkg *Package
+ exp bool
expCurPkg *Package
expMisPkg *Package
}{{
@@ -670,6 +671,7 @@ func testUpdateMissingDep(t *testing.T) {
misPkg: &Package{
ImportPath: "c",
},
+ exp: true,
expCurPkg: &Package{
ImportPath: "curpkg",
DepsMissing: []string{
@@ -691,9 +693,10 @@ func testUpdateMissingDep(t *testing.T) {
for _, c := range cases {
t.Log(c.desc)
- c.curPkg.UpdateMissingDep(c.misPkg)
+ got := c.curPkg.UpdateMissingDep(c.misPkg)
- test.Assert(t, "", c.expCurPkg, c.curPkg, true)
+ test.Assert(t, "return value", c.exp, got, true)
+ test.Assert(t, "package", c.expCurPkg, c.curPkg, true)
}
}