Compare commits
No commits in common. "master" and "v1.0.7" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,4 +7,3 @@
|
|||||||
*.iml
|
*.iml
|
||||||
out
|
out
|
||||||
gen
|
gen
|
||||||
*_test.go
|
|
39
README.md
39
README.md
@ -1,40 +1,3 @@
|
|||||||
# grsync
|
# grsync
|
||||||
|
|
||||||
```go
|
111
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"grsync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
task := grsync.NewTask(
|
|
||||||
"username@server.com:/source/folder",
|
|
||||||
"/home/user/destination",
|
|
||||||
grsync.RsyncOptions{},
|
|
||||||
)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
state := task.State()
|
|
||||||
fmt.Printf(
|
|
||||||
"progress: %.2f / rem. %d / tot. %d / sp. %s \n",
|
|
||||||
state.Progress,
|
|
||||||
state.Remain,
|
|
||||||
state.Total,
|
|
||||||
state.Speed,
|
|
||||||
)
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if err := task.Run(); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("well done")
|
|
||||||
fmt.Println(task.Log())
|
|
||||||
}
|
|
||||||
```
|
|
21
rsync.go
21
rsync.go
@ -21,17 +21,17 @@ type Rsync struct {
|
|||||||
type RsyncOptions struct {
|
type RsyncOptions struct {
|
||||||
// Verbose increase verbosity
|
// Verbose increase verbosity
|
||||||
Verbose bool
|
Verbose bool
|
||||||
// Quiet suppress non-error messages
|
// Quet suppress non-error messages
|
||||||
Quiet bool
|
Quiet bool
|
||||||
// Checksum skip based on checksum, not mod-time & size
|
// Checksum skip based on checksum, not mod-time & size
|
||||||
Checksum bool
|
Checksum bool
|
||||||
// Archive is archive mode; equals -rlptgoD (no -H,-A,-X)
|
// Archve is archive mode; equals -rlptgoD (no -H,-A,-X)
|
||||||
Archive bool
|
Archive bool
|
||||||
// Recurse into directories
|
// Recurse into directories
|
||||||
Recursive bool
|
Recursive bool
|
||||||
// Relative option to use relative path names
|
// Relative option to use relative path names
|
||||||
Relative bool
|
Relative bool
|
||||||
// NoImpliedDirs don't send implied dirs with --relative
|
// NoImliedDirs don't send implied dirs with --relative
|
||||||
NoImpliedDirs bool
|
NoImpliedDirs bool
|
||||||
// Update skip files that are newer on the receiver
|
// Update skip files that are newer on the receiver
|
||||||
Update bool
|
Update bool
|
||||||
@ -196,8 +196,7 @@ func (r Rsync) StderrPipe() (io.ReadCloser, error) {
|
|||||||
|
|
||||||
// Run start rsync task
|
// Run start rsync task
|
||||||
func (r Rsync) Run() error {
|
func (r Rsync) Run() error {
|
||||||
// 目标地址为 远程地址 则不进行文件夹创建
|
if !isExist(r.Destination) {
|
||||||
if !isRsyncPath(r.Destination) && !isExist(r.Destination) {
|
|
||||||
if err := createDir(r.Destination); err != nil {
|
if err := createDir(r.Destination); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -553,15 +552,3 @@ func isExist(p string) bool {
|
|||||||
stat, err := os.Stat(p)
|
stat, err := os.Stat(p)
|
||||||
return os.IsExist(err) && stat.IsDir()
|
return os.IsExist(err) && stat.IsDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
// isRsyncPath 判断一个给定的字符串或路径是否格式是否符合rsync协议的要求
|
|
||||||
func isRsyncPath(path string) bool {
|
|
||||||
if strings.HasPrefix(path, "rsync://") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
parts := strings.SplitN(path, ":", 2)
|
|
||||||
if len(parts) == 2 && strings.Contains(parts[0], "@") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user