From 209604d0fad5d61540bad74a0235fc0230f613c7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 1 Dec 2013 04:30:21 -0500 Subject: [PATCH] Bug fixed --- cmd/get.go | 56 ++++++++++++++++++++++++++++++++------------------- doc/github.go | 2 +- doc/google.go | 2 +- gopm.go | 2 +- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/cmd/get.go b/cmd/get.go index 0f3db4a80..a9c0cc087 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -18,6 +18,7 @@ import ( "errors" "fmt" "os" + "path" "path/filepath" "strings" @@ -31,6 +32,7 @@ import ( var ( installRepoPath string + installGopath string downloadCache map[string]bool // Saves packages that have been downloaded. downloadCount int failConut int @@ -65,19 +67,19 @@ func runGet(ctx *cli.Context) { doc.LoadPkgNameList(doc.HomeDir + "/data/pkgname.list") if ctx.Bool("gopath") { - installRepoPath = com.GetGOPATHs()[0] - if !com.IsDir(installRepoPath) { + installGopath = com.GetGOPATHs()[0] + if !com.IsDir(installGopath) { log.Error("Get", "Fail to start command") - log.Fatal("", "GOPATH does not exist: "+installRepoPath) + log.Fatal("", "GOPATH does not exist: "+installGopath) } - log.Log("Indicate GOPATH: %s", installRepoPath) + log.Log("Indicate GOPATH: %s", installGopath) - installRepoPath += "/src" - } else { - installRepoPath = doc.HomeDir + "/repos" - log.Log("Local repository path: %s", installRepoPath) + installGopath += "/src" } + installRepoPath = doc.HomeDir + "/repos" + log.Log("Local repository path: %s", installRepoPath) + // Check number of arguments. switch len(ctx.Args()) { case 0: @@ -180,6 +182,16 @@ func getByPath(ctx *cli.Context) { downloadCount, failConut) } +func copyToGopath(srcPath, destPath string) { + fmt.Println(destPath) + os.RemoveAll(destPath) + err := com.CopyDir(srcPath, destPath) + if err != nil { + log.Error("Download", "Fail to copy to GOPATH") + log.Fatal("", err.Error()) + } +} + // downloadPackages downloads packages with certain commit, // if the commit is empty string, then it downloads all dependencies, // otherwise, it only downloada package with specific commit only. @@ -188,8 +200,9 @@ func downloadPackages(ctx *cli.Context, nodes []*doc.Node) { for _, n := range nodes { // Check if it is a valid remote path. if doc.IsValidRemotePath(n.ImportPath) { - installPath := installRepoPath + "/" + doc.GetProjectPath(n.ImportPath) - if len(n.Value) > 0 && !ctx.Bool("gopath") { + gopathDir := path.Join(installGopath, n.ImportPath) + installPath := path.Join(installRepoPath, doc.GetProjectPath(n.ImportPath)) + if len(n.Value) > 0 { installPath += "." + n.Value } @@ -198,8 +211,14 @@ func downloadPackages(ctx *cli.Context, nodes []*doc.Node) { if com.IsExist(installPath) { log.Trace("Skipped installed package: %s@%s:%s", n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)) + + if ctx.Bool("gopath") { + copyToGopath(installPath, gopathDir) + } continue } + } else if !com.IsExist(installPath) { + doc.LocalNodes.SetValue(doc.GetProjectPath(n.ImportPath), "value", "") } if !downloadCache[n.ImportPath] { @@ -250,7 +269,11 @@ func downloadPackages(ctx *cli.Context, nodes []*doc.Node) { // Only save non-commit node. if len(nod.Value) == 0 && len(nod.Revision) > 0 { - doc.LocalNodes.SetValue(nod.ImportPath, "value", nod.Revision) + doc.LocalNodes.SetValue(doc.GetProjectPath(nod.ImportPath), "value", nod.Revision) + } + + if ctx.Bool("gopath") { + copyToGopath(installPath, gopathDir) } } } else { @@ -275,7 +298,7 @@ func downloadPackage(ctx *cli.Context, nod *doc.Node) (*doc.Node, []string) { // Mark as donwloaded. downloadCache[nod.ImportPath] = true - nod.Revision = doc.LocalNodes.MustValue(nod.ImportPath, "value") + nod.Revision = doc.LocalNodes.MustValue(doc.GetProjectPath(nod.ImportPath), "value") imports, err := doc.PureDownload(nod, installRepoPath, ctx) //CmdGet.Flags) if err != nil { @@ -285,15 +308,6 @@ func downloadPackage(ctx *cli.Context, nod *doc.Node) (*doc.Node, []string) { os.RemoveAll(installRepoPath + "/" + doc.GetProjectPath(nod.ImportPath) + "/") return nil, nil } - - suf := "." + nod.Value - if len(suf) == 1 { - suf = "" - } - if ctx.Bool("gopath") && len(suf) > 0 { - os.RemoveAll(installRepoPath + "/" + nod.ImportPath) - os.Rename(installRepoPath+"/"+nod.ImportPath+suf, installRepoPath+"/"+nod.ImportPath) - } return nod, imports } diff --git a/doc/github.go b/doc/github.go index 96d4d8322..c7885cbd3 100644 --- a/doc/github.go +++ b/doc/github.go @@ -70,7 +70,7 @@ func getGithubDoc(client *http.Client, match map[string]string, installRepoPath break COMMIT_LOOP } } - if etag == nod.Revision && !ctx.Bool("gopath") { + if etag == nod.Revision { log.Log("GET Package hasn't changed: %s", nod.ImportPath) return nil, nil } diff --git a/doc/google.go b/doc/google.go index 6e95bc20f..404c33a41 100644 --- a/doc/google.go +++ b/doc/google.go @@ -64,7 +64,7 @@ func getGoogleDoc(client *http.Client, match map[string]string, installRepoPath if m := googleRevisionRe.FindSubmatch(p); m == nil { log.Error("GET", "Fail to get revision") log.Error("", err.Error()) - } else if !ctx.Bool("gopath") { + } else { etag := string(m[1]) if etag == nod.Revision { log.Log("GET Package hasn't changed: %s", nod.ImportPath) diff --git a/gopm.go b/gopm.go index 7a8e289ad..5a8dd4523 100644 --- a/gopm.go +++ b/gopm.go @@ -29,7 +29,7 @@ import ( // Test that go1.1 tag above is included in builds. main.go refers to this definition. const go11tag = true -const APP_VER = "0.5.7.1130" +const APP_VER = "0.5.7.1201" // //cmd.CmdSearch, // cmdClean,