Commit ae617de8 by shenyizhong

* support windows

1 parent 76bb4781
src/config.json src/config.json
src/minsync src/minsync
src/minsync.exe
src/minsync.log src/minsync.log
src/seetadm
src/seetadm.exe
src/seetadm.log
src/Makefile src/Makefile
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
"runtime"
"strconv" "strconv"
"strings" "strings"
) )
...@@ -33,7 +34,6 @@ func init() { ...@@ -33,7 +34,6 @@ func init() {
} }
func Get(url string) ([]byte, error) { func Get(url string) ([]byte, error) {
fmt.Println(url)
resp, err := http.Get(url) resp, err := http.Get(url)
defer resp.Body.Close() defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body) body, _ := ioutil.ReadAll(resp.Body)
...@@ -133,6 +133,10 @@ func Upload(node *nodetree.NodeLoc) { ...@@ -133,6 +133,10 @@ func Upload(node *nodetree.NodeLoc) {
strCmd09 += jsonRes.Data.Key strCmd09 += jsonRes.Data.Key
strCmd10 := "file=@" strCmd10 := "file=@"
strCmd10 += node.Path strCmd10 += node.Path
if runtime.GOOS == "windows" {
strCmd10 = strings.Replace(strCmd10, "/", "\\", -1)
}
log.Printf("curl %v -F %v -F %v -F %v -F %v -F %v -F %v -F %v -F %v -F %v\n", strCmd01, strCmd02, strCmd03, strCmd04, strCmd05, strCmd06, strCmd07, strCmd08, strCmd09, strCmd10)
cmd := exec.Command("curl", strCmd01, "-F", strCmd02, "-F", strCmd03, "-F", strCmd04, "-F", strCmd05, "-F", strCmd06, "-F", strCmd07, "-F", strCmd08, "-F", strCmd09, "-F", strCmd10) cmd := exec.Command("curl", strCmd01, "-F", strCmd02, "-F", strCmd03, "-F", strCmd04, "-F", strCmd05, "-F", strCmd06, "-F", strCmd07, "-F", strCmd08, "-F", strCmd09, "-F", strCmd10)
...@@ -149,7 +153,7 @@ func Upload(node *nodetree.NodeLoc) { ...@@ -149,7 +153,7 @@ func Upload(node *nodetree.NodeLoc) {
if opBytes, err := ioutil.ReadAll(stdout); err != nil { if opBytes, err := ioutil.ReadAll(stdout); err != nil {
log.Fatal(err) log.Fatal(err)
} else { } else {
fmt.Printf("File uploaded successful : [%v]\n", node.Path) fmt.Printf("File uploaded successful : [%v] -> [%v]\n", node.Path, nodetree.StrDst+tmpStrs[1])
log.Println(string(opBytes)) log.Println(string(opBytes))
} }
} }
...@@ -168,9 +172,15 @@ func PathExists(path string) (bool, error) { ...@@ -168,9 +172,15 @@ func PathExists(path string) (bool, error) {
func MkdirLoc(path string) { func MkdirLoc(path string) {
tmpStrs := strings.Split(path, nodetree.StrSrc) tmpStrs := strings.Split(path, nodetree.StrSrc)
if len(tmpStrs) > 1 { if len(tmpStrs) > 1 {
strDir := nodetree.StrDst + "/" var strDir string
strDir += tmpStrs[1] if runtime.GOOS == "linux" {
strDir = nodetree.StrDst + "/"
}
if runtime.GOOS == "windows" {
strDir = nodetree.StrDst + "\\"
}
strDir += tmpStrs[1]
exist, err := PathExists(strDir) exist, err := PathExists(strDir)
if !exist { if !exist {
...@@ -212,7 +222,13 @@ func Download(node *nodetree.NodeRemot) { ...@@ -212,7 +222,13 @@ func Download(node *nodetree.NodeRemot) {
var jsonRes nodetree.DownloadFile var jsonRes nodetree.DownloadFile
json.Unmarshal(body, &jsonRes) json.Unmarshal(body, &jsonRes)
strDstFile := nodetree.StrDst + "/" var strDstFile string
if runtime.GOOS == "linux" {
strDstFile = nodetree.StrDst + "/"
}
if runtime.GOOS == "windows" {
strDstFile = nodetree.StrDst + "\\"
}
strDstFile += tmpStrs[1] strDstFile += tmpStrs[1]
strCmd01 := strDstFile strCmd01 := strDstFile
......
...@@ -16,18 +16,19 @@ import ( ...@@ -16,18 +16,19 @@ import (
_ "minsync/upload" _ "minsync/upload"
_ "net/http" _ "net/http"
"os" "os"
_ "runtime" "runtime"
"strings"
) )
func printUsage() { func printUsage() {
fmt.Println("Usage: minsync --token ef0c26da821c [upload|download] src dst") fmt.Println("Usage: seetadm --token ef0c26da821c [upload|download] src dst")
} }
func main() { func main() {
fmt.Println("minsync v0.0.2") fmt.Println("seetadm v0.0.2")
// minsync --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 {
printUsage() printUsage()
return return
...@@ -51,13 +52,21 @@ func main() { ...@@ -51,13 +52,21 @@ func main() {
} }
fmt.Printf("%v %v %v %v\n", nodetree.StrToken, nodetree.StrOp, nodetree.StrSrc, nodetree.StrDst) fmt.Printf("%v %v %v %v\n", nodetree.StrToken, nodetree.StrOp, nodetree.StrSrc, nodetree.StrDst)
if runtime.GOOS == "windows" {
nodetree.StrSrc = strings.Replace(nodetree.StrSrc, "\\", "/", -1)
nodetree.StrDst = strings.Replace(nodetree.StrDst, "\\", "/", -1)
}
// check dst format // check dst format
if nodetree.StrDst[len(nodetree.StrDst)-1:] != "/" { lastStrDst := nodetree.StrDst[len(nodetree.StrDst)-1:]
lastStrSrc := nodetree.StrSrc[len(nodetree.StrSrc)-1:]
if lastStrDst != "/" {
fmt.Printf("target path [%v] format error, need end with /\n", nodetree.StrDst) fmt.Printf("target path [%v] format error, need end with /\n", nodetree.StrDst)
return return
} }
if nodetree.StrSrc[len(nodetree.StrSrc)-1:] != "/" { if lastStrSrc != "/" {
fmt.Printf("source path [%v] format error, need end with /\n", nodetree.StrSrc) fmt.Printf("source path [%v] format error, need end with /\n", nodetree.StrSrc)
return return
} }
......
...@@ -93,7 +93,7 @@ var StrToken string ...@@ -93,7 +93,7 @@ var StrToken string
func init() { func init() {
logFile, err := os.OpenFile("./minsync.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644) logFile, err := os.OpenFile("./seetadm.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil { if err != nil {
fmt.Println("open log file failed, err:", err) fmt.Println("open log file failed, err:", err)
return return
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!