Commit 41f20bde by shenyizhong

* check target path at upload

1 parent d61e4dbf
Showing with 52 additions and 5 deletions
...@@ -234,15 +234,54 @@ func Upload(node *nodetree.NodeLoc) (def.ErrCode, error) { ...@@ -234,15 +234,54 @@ func Upload(node *nodetree.NodeLoc) (def.ErrCode, error) {
return def.SUCCESS, nil return def.SUCCESS, nil
} }
func PathExists(path string) (bool, error) { func RemotPathExists(path string) (def.ErrCode, error) {
url := "http://"
url += host
url += ":"
url += strconv.Itoa(port)
url += "/front/data/query_list?pages=1&pagesize=10&prefix="
url += path
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Println(err)
return def.ERR_HTTP_REQUEST, err
}
req.Header.Add("token", auth.GetToken())
var resp *http.Response
resp, err = http.DefaultClient.Do(req)
if err != nil {
log.Println(err)
return def.ERR_HTTP_REQUEST, err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println(err)
return def.ERR_UNKNOWN, err
}
var dl SvrResp
json.Unmarshal(body, &dl)
if dl.Msg != "OK" {
return def.ERR_PATH_NOT_EXISTED, nil
}
return def.SUCCESS, nil
}
func PathExists(path string) (def.ErrCode, error) {
_, err := os.Stat(path) _, err := os.Stat(path)
if err == nil { if err == nil {
return true, nil return def.SUCCESS, nil
} }
if os.IsNotExist(err) { if os.IsNotExist(err) {
return false, nil return def.ERR_PATH_NOT_EXISTED, nil
} }
return false, err return def.ERR_PATH_NOT_EXISTED, nil
} }
func MkdirLoc(path string) (def.ErrCode, error) { func MkdirLoc(path string) (def.ErrCode, error) {
...@@ -262,7 +301,7 @@ func MkdirLoc(path string) (def.ErrCode, error) { ...@@ -262,7 +301,7 @@ func MkdirLoc(path string) (def.ErrCode, error) {
return def.ERR_PATH_HAS_EXISTED, err return def.ERR_PATH_HAS_EXISTED, err
} }
if !exist { if exist == def.ERR_PATH_NOT_EXISTED {
err = os.Mkdir(strDir, 0775) err = os.Mkdir(strDir, 0775)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
......
...@@ -124,6 +124,14 @@ func main() { ...@@ -124,6 +124,14 @@ func main() {
if nodetree.StrOp == "upload" { if nodetree.StrOp == "upload" {
nodetree.StrDst = "data" + nodetree.StrDst nodetree.StrDst = "data" + nodetree.StrDst
remot_dst, err := httpcli.RemotPathExists(nodetree.StrDst)
if err != nil {
return
}
if remot_dst == def.ERR_PATH_NOT_EXISTED {
fmt.Printf("target path not exist on server\n")
return
}
tmpstr := nodetree.StrSrc[:len(nodetree.StrSrc)-1] tmpstr := nodetree.StrSrc[:len(nodetree.StrSrc)-1]
idx := strings.LastIndex(tmpstr, "/") idx := strings.LastIndex(tmpstr, "/")
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!