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 ae617de8
authored
Jan 06, 2022
by
shenyizhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* support windows
1 parent
76bb4781
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
12 deletions
.gitignore
src/httpcli/httpcli.go
src/main.go
src/nodetree/nodetree.go
.gitignore
View file @
ae617de
src/config.json
src/minsync
src/minsync.exe
src/minsync.log
src/seetadm
src/seetadm.exe
src/seetadm.log
src/Makefile
src/httpcli/httpcli.go
View file @
ae617de
...
...
@@ -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
...
...
src/main.go
View file @
ae617de
...
...
@@ -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
}
...
...
src/nodetree/nodetree.go
View file @
ae617de
...
...
@@ -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
...
...
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