Commit 6124dc0a by shenyizhong

* code review

1 parent ae617de8
package httpcli package httpcli
import ( import (
"bufio"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"log" "log"
"minsync/auth" "minsync/auth"
...@@ -192,10 +194,10 @@ func MkdirLoc(path string) { ...@@ -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) tmpStrs := strings.Split(node.Name, nodetree.StrSrc)
if len(tmpStrs) < 2 { if len(tmpStrs) < 2 {
return return nil
} }
// "/front/data/download?name=data/folder3/ddd.txt" // "/front/data/download?name=data/folder3/ddd.txt"
...@@ -231,26 +233,26 @@ func Download(node *nodetree.NodeRemot) { ...@@ -231,26 +233,26 @@ func Download(node *nodetree.NodeRemot) {
} }
strDstFile += tmpStrs[1] strDstFile += tmpStrs[1]
strCmd01 := strDstFile log.Printf("wget -O %v \"%v\"", strDstFile, jsonRes.Data.Url)
strCmd02 := "\"" + jsonRes.Data.Url + "\""
cmd := exec.Command("wget", "-O", strCmd01, strCmd02)
stdout, err := cmd.StdoutPipe() res, err := http.Get(jsonRes.Data.Url)
if err != nil { 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 { file, err := os.Create(strDstFile)
log.Fatal(err) if err != nil {
panic(err)
} }
// 获得文件的writer对象
writer := bufio.NewWriter(file)
if opBytes, err := ioutil.ReadAll(stdout); err != nil { written, _ := io.Copy(writer, reader)
log.Fatal(err) fmt.Printf("File download successful : [%v] -> [%v], %v written\n", nodetree.StrSrc+tmpStrs[1], strDstFile, written)
} else {
fmt.Printf("File download successful : [%v] -> [%v]\n", node.Name, strDstFile)
log.Println(string(opBytes))
}
return nil
} }
...@@ -26,7 +26,7 @@ func printUsage() { ...@@ -26,7 +26,7 @@ func printUsage() {
func main() { func main() {
fmt.Println("seetadm v0.0.2") fmt.Println("seetadm v0.0.3")
// seetadm --token ef0c26da821c upload /home/syz/tmp/abc /part1/box2 // seetadm --token ef0c26da821c upload /home/syz/tmp/abc /part1/box2
if len(os.Args) < 6 { if len(os.Args) < 6 {
......
...@@ -66,6 +66,7 @@ func exploreRecursive(node *nodetree.NodeLoc, option *nodetree.OptionLoc, op str ...@@ -66,6 +66,7 @@ func exploreRecursive(node *nodetree.NodeLoc, option *nodetree.OptionLoc, op str
// mkdir remot // mkdir remot
httpcli.MkdirRemot(child.Path) httpcli.MkdirRemot(child.Path)
log.Printf("MkdirRemot(%v)", child.Path)
if option.SubFlag { if option.SubFlag {
if !IsInSlice(option.IgnorePath, f.Name()) { 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!