From 90cd6f655d7053e23448836d12e68f02c6fe50e1 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 19 May 2013 16:05:46 -0400 Subject: [PATCH] finish command: install, support github.com only --- conf/gpm.toml | 2 +- doc/github.go | 10 +++++++--- doc/walker.go | 3 ++- install.go | 42 +++++++++++++++++++++++------------------- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/conf/gpm.toml b/conf/gpm.toml index 7757b2316..144841e0a 100644 --- a/conf/gpm.toml +++ b/conf/gpm.toml @@ -1,5 +1,5 @@ # This is a configuration file for gpm with toml format. title = "gpm(Go Package Manager)" -version = "v0.0.2 Build 0519" +version = "v0.0.3 Build 0519" user_language = "en-US" \ No newline at end of file diff --git a/doc/github.go b/doc/github.go index 0c2f41493..392439a20 100644 --- a/doc/github.go +++ b/doc/github.go @@ -98,6 +98,7 @@ func GetGithubDoc(client *http.Client, match map[string]string, commit string) ( // Create destination directory. os.Mkdir(installPath, os.ModePerm) + //dirMap := make(map[string][]*source) dirs := make([]string, 0, 5) for _, f := range r.File { absPath := strings.Replace(f.FileInfo().Name(), shaName, installPath, 1) @@ -124,6 +125,8 @@ func GetGithubDoc(client *http.Client, match map[string]string, commit string) ( } _, err = io.Copy(fw, rc) + rc.Close() + fw.Close() if err != nil { return nil, nil, err } @@ -156,20 +159,21 @@ func GetGithubDoc(client *http.Client, match map[string]string, commit string) ( for _, fi := range fis { // Only handle files. if strings.HasSuffix(fi.Name(), ".go") { - f, err := os.Open(d + "/" + fi.Name()) + f, err := os.Open(d + fi.Name()) if err != nil { return nil, nil, err } - defer f.Close() fbytes := make([]byte, fi.Size()) _, err = f.Read(fbytes) + f.Close() + //fmt.Println(d+fi.Name(), fi.Size(), n) if err != nil { return nil, nil, err } files = append(files, &source{ - name: importPath + "/" + fi.Name(), + name: fi.Name(), data: fbytes, }) } diff --git a/doc/walker.go b/doc/walker.go index 31ee21b77..b9f3a247a 100644 --- a/doc/walker.go +++ b/doc/walker.go @@ -136,9 +136,10 @@ func (w *walker) build(srcs []*source) ([]string, error) { var imports []string for _, v := range bpkg.Imports { // Skip strandard library. - if !utils.IsGoRepoPath(v) { + if !utils.IsGoRepoPath(v) && v != w.ImportPath { imports = append(imports, v) } } + return imports, err } diff --git a/install.go b/install.go index 1d0424cda..d3e4d1d1c 100644 --- a/install.go +++ b/install.go @@ -105,7 +105,7 @@ func runInstall(cmd *Command, args []string) { commits := make([]string, len(args)) downloadPackages(args, commits) - if !cmdInstall.Flags["d"] { + if !cmdInstall.Flags["d"] && cmdInstall.Flags["-p"] { // Install packages all together. fmt.Printf("Installing package: %s.\n") } @@ -125,20 +125,24 @@ func downloadPackages(pkgs, commits []string) { // TODO: api.GetBundleInfo() case p[0] == 'S': // TODO: api.GetSnapshotInfo() - case utils.IsValidRemotePath(p) && !downloadCache[p]: - // Download package. - pkg, imports := downloadPackage(p, commits[i]) - if len(imports) > 0 { - // Need to download dependencies. - tags := make([]string, len(imports)) - downloadPackages(imports, tags) - continue - } - - // Only save package information with specific commit. - if pkg != nil { - // Save record in local database. - fmt.Printf("Saved information: %s:%s.\n", pkg.ImportPath, pkg.Commit) + case utils.IsValidRemotePath(p): + if !downloadCache[p] { + // Download package. + pkg, imports := downloadPackage(p, commits[i]) + if len(imports) > 0 { + // Need to download dependencies. + tags := make([]string, len(imports)) + downloadPackages(imports, tags) + continue + } + + // Only save package information with specific commit. + if pkg != nil { + // Save record in local database. + //fmt.Printf("Saved information: %s:%s.\n", pkg.ImportPath, pkg.Commit) + } + } else { + fmt.Printf("Skipped downloaded package: %s.\n", p) } default: // Invalid import path. @@ -173,11 +177,11 @@ func downloadPackage(path, commit string) (pkg *doc.Package, imports []string) { if err != nil { fmt.Printf("Fail to download package(%s) with error: %s.\n", path, err) return nil, nil - } else { - fmt.Println(pkg) - fmt.Printf("Downloaded package: %s.\n", path) - return pkg, imports } + + //fmt.Println(pkg) + //fmt.Printf("Downloaded package: %s.\n", path) + return pkg, imports } }