Commit 6124dc0a by shenyizhong

* code review

1 parent ae617de8
package httpcli
import (
"bufio"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"minsync/auth"
......@@ -192,10 +194,10 @@ func MkdirLoc(path string) {
}
}
func Download(node *nodetree.NodeRemot) {
func Download(node *nodetree.NodeRemot) error {
tmpStrs := strings.Split(node.Name, nodetree.StrSrc)
if len(tmpStrs) < 2 {
return
return nil
}
// "/front/data/download?name=data/folder3/ddd.txt"
......@@ -231,26 +233,26 @@ func Download(node *nodetree.NodeRemot) {
}
strDstFile += tmpStrs[1]
strCmd01 := strDstFile
strCmd02 := "\"" + jsonRes.Data.Url + "\""
cmd := exec.Command("wget", "-O", strCmd01, strCmd02)
log.Printf("wget -O %v \"%v\"", strDstFile, jsonRes.Data.Url)
stdout, err := cmd.StdoutPipe()
res, err := http.Get(jsonRes.Data.Url)
if err != nil {
log.Fatal(err)
fmt.Println("error occurred!")
return err
}
defer stdout.Close()
defer res.Body.Close()
// 获得get请求响应的reader对象
reader := bufio.NewReaderSize(res.Body, 32*1024)
if err := cmd.Start(); err != nil {
log.Fatal(err)
file, err := os.Create(strDstFile)
if err != nil {
panic(err)
}
// 获得文件的writer对象
writer := bufio.NewWriter(file)
if opBytes, err := ioutil.ReadAll(stdout); err != nil {
log.Fatal(err)
} else {
fmt.Printf("File download successful : [%v] -> [%v]\n", node.Name, strDstFile)
log.Println(string(opBytes))
}
written, _ := io.Copy(writer, reader)
fmt.Printf("File download successful : [%v] -> [%v], %v written\n", nodetree.StrSrc+tmpStrs[1], strDstFile, written)
return nil
}
......@@ -26,7 +26,7 @@ func printUsage() {
func main() {
fmt.Println("seetadm v0.0.2")
fmt.Println("seetadm v0.0.3")
// seetadm --token ef0c26da821c upload /home/syz/tmp/abc /part1/box2
if len(os.Args) < 6 {
......
......@@ -66,6 +66,7 @@ func exploreRecursive(node *nodetree.NodeLoc, option *nodetree.OptionLoc, op str
// mkdir remot
httpcli.MkdirRemot(child.Path)
log.Printf("MkdirRemot(%v)", child.Path)
if option.SubFlag {
if !IsInSlice(option.IgnorePath, f.Name()) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!