Browse Source

Updated download check

pull/103/head
Unknown 12 years ago
parent
commit
ec4cf895d5
  1. 23
      cmd/get.go
  2. 18
      doc/github.go
  3. 11
      doc/struct.go

23
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")

18
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)))

11
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 {

Loading…
Cancel
Save