aboutsummaryrefslogtreecommitdiffsponsor
path: root/internal/service/rsync.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/service/rsync.go')
-rw-r--r--internal/service/rsync.go40
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
+}