From ec4cf895d50d07fa07373ae82ea5881a63d7e269 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 18 Aug 2013 19:39:28 +0800 Subject: [PATCH] Updated download check --- cmd/get.go | 23 ++++++++++++++++++----- doc/github.go | 18 +++++++++++------- doc/struct.go | 11 ++++++----- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/cmd/get.go b/cmd/get.go index 96f5ffb7a..0b41c684b 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -133,7 +133,7 @@ func runGet(cmd *Command, args []string) { nodes := []*doc.Node{} // ver describles branch, tag or commit. - var t, ver string = doc.BRANCH, doc.TRUNK + var t, ver string = doc.BRANCH, "" if len(args) >= 2 { t, ver, err = validPath(args[1]) @@ -166,7 +166,11 @@ func downloadPackages(nodes []*doc.Node) { if doc.IsValidRemotePath(n.ImportPath) { if !CmdGet.Flags["-u"] { // Check if package has been downloaded. - if _, ok := doc.CheckIsExistInGOPATH(n.ImportPath); ok { + installPath := installRepoPath + "/" + n.ImportPath + if len(n.Value) > 0 { + installPath += "." + n.Value + } + if doc.IsExist(installPath) { doc.ColorLog("[WARN] Skipped installed package( %s => %s:%s )\n", n.ImportPath, n.Type, n.Value) continue @@ -181,8 +185,11 @@ func downloadPackages(nodes []*doc.Node) { // Generate temporary nodes. nodes := make([]*doc.Node, len(imports)) for i := range nodes { - nodes[i] = new(doc.Node) - nodes[i].ImportPath = imports[i] + nodes[i] = &doc.Node{ + ImportPath: imports[i], + Type: doc.BRANCH, + IsGetDeps: true, + } } downloadPackages(nodes) } @@ -209,6 +216,8 @@ func downloadPackages(nodes []*doc.Node) { // downloadPackage downloads package either use version control tools or not. func downloadPackage(nod *doc.Node) (*doc.Node, []string) { + doc.ColorLog("[TRAC] Downloading package( %s => %s:%s )\n", + nod.ImportPath, nod.Type, nod.Value) // Mark as donwloaded. downloadCache[nod.ImportPath] = true @@ -230,8 +239,12 @@ func validPath(info string) (string, string, error) { case l > 2: return "", "", errors.New("Invalid information of package") case l == 1: - return doc.BRANCH, doc.TRUNK, nil + return doc.BRANCH, "", nil case l == 2: + switch infos[1] { + case doc.TRUNK, doc.MASTER, doc.DEFAULT: + infos[1] = "" + } return infos[0], infos[1], nil default: return "", "", errors.New("Cannot match any case") diff --git a/doc/github.go b/doc/github.go index fd025a489..1fe87db67 100644 --- a/doc/github.go +++ b/doc/github.go @@ -47,13 +47,13 @@ func GetGithubDoc(client *http.Client, match map[string]string, installRepoPath match["cred"] = githubCred if nod.Type == BRANCH { - nod.Value = MASTER - match["sha"] = nod.Value + if len(nod.Value) == 0 { + match["sha"] = MASTER + } else { + match["sha"] = nod.Value + } } - ColorLog("[TRAC] Downloading package( %s => %s:%s )\n", - nod.ImportPath, nod.Type, nod.Value) - // JSON struct for github.com. var refs []*struct { Ref string @@ -107,13 +107,17 @@ func GetGithubDoc(client *http.Client, match map[string]string, installRepoPath shaName = strings.Replace(shaName, "-v", "-", 1) } + suf := "." + nod.Value + if len(suf) == 1 { + suf = "" + } + projectPath := expand("github.com/{owner}/{repo}", match) - installPath := installRepoPath + "/" + projectPath + "." + nod.Value + installPath := installRepoPath + "/" + projectPath + suf nod.ImportPath = projectPath // Remove old files. os.RemoveAll(installPath + "/") - // Create destination directory. os.MkdirAll(installPath+"/", os.ModePerm) r, err := zip.NewReader(bytes.NewReader(p), int64(len(p))) diff --git a/doc/struct.go b/doc/struct.go index 16bb7a2ec..96b769e83 100644 --- a/doc/struct.go +++ b/doc/struct.go @@ -21,11 +21,12 @@ import ( ) const ( - TRUNK = "trunk" - MASTER = "master" - TAG = "tag" - BRANCH = "branch" - COMMIT = "commit" + TRUNK = "trunk" + MASTER = "master" + DEFAULT = "default" + TAG = "tag" + BRANCH = "branch" + COMMIT = "commit" ) type Node struct {