diff --git a/cmd/get.go b/cmd/get.go index 6ae456e8c..684ceea03 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -17,6 +17,7 @@ package cmd import ( "errors" "fmt" + //"os" "strings" "github.com/Unknwon/com" @@ -226,8 +227,9 @@ func downloadPackage(nod *doc.Node) (*doc.Node, []string) { imports, err := doc.PureDownload(nod, installRepoPath, CmdGet.Flags) if err != nil { - com.ColorLog("[ERRO] Download falied[ %s ]\n", err) + com.ColorLog("[ERRO] Download falied( %s )[ %s ]\n", nod.ImportPath, err) failConut++ + //os.RemoveAll(installRepoPath + "/" + doc.GetProjectPath(nod.ImportPath) + "/") return nil, nil } return nod, imports diff --git a/doc/github.go b/doc/github.go index 686234040..a47c39a94 100644 --- a/doc/github.go +++ b/doc/github.go @@ -107,21 +107,18 @@ func getGithubDoc(client *http.Client, match map[string]string, installRepoPath } default: // Get file from archive. - rc, err := f.Open() + r, err := f.Open() if err != nil { return nil, err } - // Write data to file - fw, _ := os.Create(absPath) + fbytes := make([]byte, f.FileInfo().Size()) + _, err = io.ReadFull(r, fbytes) if err != nil { return nil, err } - _, err = io.Copy(fw, rc) - // Close files. - rc.Close() - fw.Close() + _, err = com.SaveFile(absPath, fbytes) if err != nil { return nil, err } diff --git a/doc/google.go b/doc/google.go index fae9d9b82..18ab3e4f2 100644 --- a/doc/google.go +++ b/doc/google.go @@ -40,7 +40,7 @@ func getGoogleDoc(client *http.Client, match map[string]string, installRepoPath setupGoogleMatch(match) // Check version control. if err := getGoogleVCS(client, match); err != nil { - return nil, err + return nil, errors.New("fail to get vcs " + nod.ImportPath + " : " + err.Error()) } switch nod.Type { @@ -112,33 +112,37 @@ func getGoogleDoc(client *http.Client, match map[string]string, installRepoPath } // Get file from archive. - rc, err := f.Open() + r, err := f.Open() if err != nil { return nil, err } - // Write data to file - fw, _ := os.Create(absPath) + fbytes := make([]byte, f.FileInfo().Size()) + _, err = io.ReadFull(r, fbytes) if err != nil { return nil, err } - _, err = io.Copy(fw, rc) - // Close files. - rc.Close() - fw.Close() + _, err = com.SaveFile(absPath, fbytes) if err != nil { return nil, err } } + var imports []string + // Check if need to check imports. if nod.IsGetDeps { - imports := getImports(installPath+"/", match, cmdFlags, nod) - return imports, err + for _, d := range dirs { + importPkgs, err := CheckImports(d, match["importPath"], nod) + if err != nil { + return nil, err + } + imports = append(imports, importPkgs...) + } } - return nil, err + return imports, err } type rawFile struct { diff --git a/doc/oschina.go b/doc/oschina.go index 651651adb..ab3777c3a 100644 --- a/doc/oschina.go +++ b/doc/oschina.go @@ -93,21 +93,18 @@ func getOSCDoc(client *http.Client, match map[string]string, installRepoPath str } // Get file from archive. - rc, err := f.Open() + r, err := f.Open() if err != nil { return nil, errors.New("Fail to open OSChina repo -> " + err.Error()) } - // Write data to file - fw, _ := os.Create(absPath) + fbytes := make([]byte, f.FileInfo().Size()) + _, err = io.ReadFull(r, fbytes) if err != nil { return nil, err } - _, err = io.Copy(fw, rc) - // Close files. - rc.Close() - fw.Close() + _, err = com.SaveFile(absPath, fbytes) if err != nil { return nil, err }