Permalink
Browse files

Do not download nuts twice.

  • Loading branch information...
1 parent 6af8103 commit 6c540f7b37dd0491ad836a45b15d56faf7acdaf6 @AlekSi committed Mar 3, 2013
Showing with 26 additions and 7 deletions.
  1. +13 −2 integration_test/remote_test.go
  2. +13 −5 nut/get.go
@@ -49,6 +49,10 @@ func (*R) TestPublishGet(c *C) {
c.Check(strings.HasSuffix(stderr, `test_nut2-0.0.2.nut created.`), Equals, true)
gitNoDiff(c, TestNut2)
+ _, stderr = runNut(c, TestNut3, "pack -v")
+ c.Check(strings.HasSuffix(stderr, `test_nut3-0.0.3.nut created.`), Equals, true)
+ gitNoDiff(c, TestNut3)
+
_, stderr = runNut(c, TestNut1, "publish -v test_nut1-0.0.1.nut")
c.Check(strings.HasSuffix(stderr, `Nut debug/test_nut1 version 0.0.1 published.`), Equals, true)
gitNoDiff(c, TestNut1)
@@ -61,6 +65,13 @@ func (*R) TestPublishGet(c *C) {
c.Check(strings.HasSuffix(stderr, `Nut debug/test_nut2 version 0.0.2 published.`), Equals, true)
gitNoDiff(c, TestNut2)
- _, stderr = runNut(c, "", "get -v debug/test_nut2/0.0.2")
- c.Check(strings.HasSuffix(stderr, `gonuts.io/debug/test_nut2`), Equals, true)
+ _, stderr = runNut(c, TestNut3, "publish -v test_nut3-0.0.3.nut")
+ c.Check(strings.HasSuffix(stderr, `Nut debug/test_nut3 version 0.0.3 published.`), Equals, true)
+ gitNoDiff(c, TestNut3)
+
+ _, stderr = runNut(c, "", "get -v debug/test_nut3/0.0.3")
+ c.Check(strings.Count(stderr, "gonuts.io/test_nut1-0.0.1.nut"), Equals, 1)
+ c.Check(strings.Count(stderr, "gonuts.io/test_nut2-0.0.2.nut"), Equals, 1)
+ c.Check(strings.Count(stderr, "gonuts.io/test_nut3-0.0.3.nut"), Equals, 1)
+ c.Check(strings.HasSuffix(stderr, `gonuts.io/debug/test_nut3`), Equals, true)
}
View
@@ -141,12 +141,19 @@ func runGet(cmd *Command) {
}
}
- installPaths := make(map[string]bool, len(args))
+ urlsToPaths := make(map[string]string, len(args))
for len(args) != 0 {
arg := args[0]
args = args[1:]
url, prefix := ParseArg(arg)
+
+ // do not download twice
+ _, present := urlsToPaths[url.String()]
+ if present {
+ continue
+ }
+
b, err := get(url)
if err != nil {
log.Print(err)
@@ -169,7 +176,7 @@ func runGet(cmd *Command) {
FatalIfErr(err)
deps := NutImports(nf.Imports)
if getV && len(deps) != 0 {
- log.Printf("%s depends on nuts: %s", nf.Name, strings.Join(deps, ","))
+ log.Printf("%s depends on nuts: %s", nf.Name, strings.Join(deps, ", "))
}
args = append(args, deps...)
@@ -180,11 +187,12 @@ func runGet(cmd *Command) {
fileName := WriteNut(b, p, getV)
path := nf.ImportPath(p)
UnpackNut(fileName, filepath.Join(SrcDir, path), true, getV)
- installPaths[path] = true
+ urlsToPaths[url.String()] = path
}
- paths := make([]string, 0, len(installPaths))
- for path := range installPaths {
+ // install in lexical order (useful in integration tests)
+ paths := make([]string, 0, len(urlsToPaths))
+ for _, path := range urlsToPaths {
paths = append(paths, path)
}
sort.Strings(paths)

0 comments on commit 6c540f7

Please sign in to comment.