Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
shenyizhong
/
minsync
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 41f20bde
authored
Jan 17, 2022
by
shenyizhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* check target path at upload
1 parent
d61e4dbf
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
5 deletions
src/httpcli/httpcli.go
src/main.go
src/httpcli/httpcli.go
View file @
41f20bd
...
...
@@ -234,15 +234,54 @@ func Upload(node *nodetree.NodeLoc) (def.ErrCode, error) {
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
)
if
err
==
nil
{
return
true
,
nil
return
def
.
SUCCESS
,
nil
}
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
)
{
...
...
@@ -262,7 +301,7 @@ func MkdirLoc(path string) (def.ErrCode, error) {
return
def
.
ERR_PATH_HAS_EXISTED
,
err
}
if
!
exist
{
if
exist
==
def
.
ERR_PATH_NOT_EXISTED
{
err
=
os
.
Mkdir
(
strDir
,
0775
)
if
err
!=
nil
{
log
.
Println
(
err
)
...
...
src/main.go
View file @
41f20bd
...
...
@@ -124,6 +124,14 @@ func main() {
if
nodetree
.
StrOp
==
"upload"
{
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
]
idx
:=
strings
.
LastIndex
(
tmpstr
,
"/"
)
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment