From ae748859be8d6d3ed3c0929770f0c287ab6d6460 Mon Sep 17 00:00:00 2001 From: Slack Coder Date: Mon, 8 Apr 2024 15:29:11 -0500 Subject: Port to Golang --- internal/service/rsync.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 internal/service/rsync.go (limited to 'internal/service/rsync.go') 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 +} -- cgit v1.2.3