diff options
author | Slack Coder <slackcoder@server.ky> | 2024-04-08 15:29:11 -0500 |
---|---|---|
committer | Slack Coder <slackcoder@server.ky> | 2024-07-18 11:47:49 -0500 |
commit | ae748859be8d6d3ed3c0929770f0c287ab6d6460 (patch) | |
tree | 284d3bf3d7fa496a9d334391eac996affc5a01b9 /internal/service/rsync.go | |
parent | c2267767ca8ed06018d26a45b483c44b7c4234cf (diff) | |
download | mirror-ae748859be8d6d3ed3c0929770f0c287ab6d6460.tar.xz |
Port to Golangv0.0.1-dev
Diffstat (limited to 'internal/service/rsync.go')
-rw-r--r-- | internal/service/rsync.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/service/rsync.go b/internal/service/rsync.go new file mode 100644 index 0000000..8298589 --- /dev/null +++ b/internal/service/rsync.go @@ -0,0 +1,40 @@ +package service + +import ( + "bytes" + "errors" + "net/url" + "os/exec" + "strings" +) + +var rsyncOpts = []string{ + "--delete-excluded", + "--hard-links", + "--links", + "--perms", + "--recursive", + "--safe-links", + "--sparse", + "--times", +} + +func Rsync(dst *url.URL, src *url.URL) error { + src2 := *src + if !strings.HasSuffix(src2.Path, "/.") { + src2.Path = src2.Path + "/." + } + + var stderr bytes.Buffer + + args := append(rsyncOpts, src2.String(), dst.String()) + cmd := exec.Command("rsync", args...) + cmd.Stderr = &stderr + + err := cmd.Run() + if err != nil { + return errors.New(stderr.String()) + } + + return nil +} |