Browse Source

Bug fixed

pull/103/head
Unknown 11 years ago
parent
commit
209604d0fa
  1. 56
      cmd/get.go
  2. 2
      doc/github.go
  3. 2
      doc/google.go
  4. 2
      gopm.go

56
cmd/get.go

@ -18,6 +18,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
@ -31,6 +32,7 @@ import (
var ( var (
installRepoPath string installRepoPath string
installGopath string
downloadCache map[string]bool // Saves packages that have been downloaded. downloadCache map[string]bool // Saves packages that have been downloaded.
downloadCount int downloadCount int
failConut int failConut int
@ -65,19 +67,19 @@ func runGet(ctx *cli.Context) {
doc.LoadPkgNameList(doc.HomeDir + "/data/pkgname.list") doc.LoadPkgNameList(doc.HomeDir + "/data/pkgname.list")
if ctx.Bool("gopath") { if ctx.Bool("gopath") {
installRepoPath = com.GetGOPATHs()[0] installGopath = com.GetGOPATHs()[0]
if !com.IsDir(installRepoPath) { if !com.IsDir(installGopath) {
log.Error("Get", "Fail to start command") 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" installGopath += "/src"
} else {
installRepoPath = doc.HomeDir + "/repos"
log.Log("Local repository path: %s", installRepoPath)
} }
installRepoPath = doc.HomeDir + "/repos"
log.Log("Local repository path: %s", installRepoPath)
// Check number of arguments. // Check number of arguments.
switch len(ctx.Args()) { switch len(ctx.Args()) {
case 0: case 0:
@ -180,6 +182,16 @@ func getByPath(ctx *cli.Context) {
downloadCount, failConut) 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, // downloadPackages downloads packages with certain commit,
// if the commit is empty string, then it downloads all dependencies, // if the commit is empty string, then it downloads all dependencies,
// otherwise, it only downloada package with specific commit only. // 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 { for _, n := range nodes {
// Check if it is a valid remote path. // Check if it is a valid remote path.
if doc.IsValidRemotePath(n.ImportPath) { if doc.IsValidRemotePath(n.ImportPath) {
installPath := installRepoPath + "/" + doc.GetProjectPath(n.ImportPath) gopathDir := path.Join(installGopath, n.ImportPath)
if len(n.Value) > 0 && !ctx.Bool("gopath") { installPath := path.Join(installRepoPath, doc.GetProjectPath(n.ImportPath))
if len(n.Value) > 0 {
installPath += "." + n.Value installPath += "." + n.Value
} }
@ -198,8 +211,14 @@ func downloadPackages(ctx *cli.Context, nodes []*doc.Node) {
if com.IsExist(installPath) { if com.IsExist(installPath) {
log.Trace("Skipped installed package: %s@%s:%s", log.Trace("Skipped installed package: %s@%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)) n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
if ctx.Bool("gopath") {
copyToGopath(installPath, gopathDir)
}
continue continue
} }
} else if !com.IsExist(installPath) {
doc.LocalNodes.SetValue(doc.GetProjectPath(n.ImportPath), "value", "")
} }
if !downloadCache[n.ImportPath] { if !downloadCache[n.ImportPath] {
@ -250,7 +269,11 @@ func downloadPackages(ctx *cli.Context, nodes []*doc.Node) {
// Only save non-commit node. // Only save non-commit node.
if len(nod.Value) == 0 && len(nod.Revision) > 0 { 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 { } else {
@ -275,7 +298,7 @@ func downloadPackage(ctx *cli.Context, nod *doc.Node) (*doc.Node, []string) {
// Mark as donwloaded. // Mark as donwloaded.
downloadCache[nod.ImportPath] = true 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) imports, err := doc.PureDownload(nod, installRepoPath, ctx) //CmdGet.Flags)
if err != nil { 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) + "/") os.RemoveAll(installRepoPath + "/" + doc.GetProjectPath(nod.ImportPath) + "/")
return nil, nil 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 return nod, imports
} }

2
doc/github.go

@ -70,7 +70,7 @@ func getGithubDoc(client *http.Client, match map[string]string, installRepoPath
break COMMIT_LOOP break COMMIT_LOOP
} }
} }
if etag == nod.Revision && !ctx.Bool("gopath") { if etag == nod.Revision {
log.Log("GET Package hasn't changed: %s", nod.ImportPath) log.Log("GET Package hasn't changed: %s", nod.ImportPath)
return nil, nil return nil, nil
} }

2
doc/google.go

@ -64,7 +64,7 @@ func getGoogleDoc(client *http.Client, match map[string]string, installRepoPath
if m := googleRevisionRe.FindSubmatch(p); m == nil { if m := googleRevisionRe.FindSubmatch(p); m == nil {
log.Error("GET", "Fail to get revision") log.Error("GET", "Fail to get revision")
log.Error("", err.Error()) log.Error("", err.Error())
} else if !ctx.Bool("gopath") { } else {
etag := string(m[1]) etag := string(m[1])
if etag == nod.Revision { if etag == nod.Revision {
log.Log("GET Package hasn't changed: %s", nod.ImportPath) log.Log("GET Package hasn't changed: %s", nod.ImportPath)

2
gopm.go

@ -29,7 +29,7 @@ import (
// Test that go1.1 tag above is included in builds. main.go refers to this definition. // Test that go1.1 tag above is included in builds. main.go refers to this definition.
const go11tag = true const go11tag = true
const APP_VER = "0.5.7.1130" const APP_VER = "0.5.7.1201"
// //cmd.CmdSearch, // //cmd.CmdSearch,
// cmdClean, // cmdClean,

Loading…
Cancel
Save