Commit ae617de8 by shenyizhong

* support windows

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