mirror

Mirror free and open-source projects you like with minimal effort
git clone git://git.server.ky/slackcoder/mirror
Log | Files | Refs | README

rsync.go (647B)


      1 package service
      2 
      3 import (
      4 	"bytes"
      5 	"errors"
      6 	"os/exec"
      7 	"strings"
      8 
      9 	"git.server.ky/slackcoder/mirror/internal"
     10 )
     11 
     12 var rsyncOpts = []string{
     13 	"--delete-excluded",
     14 	"--hard-links",
     15 	"--links",
     16 	"--perms",
     17 	"--recursive",
     18 	"--safe-links",
     19 	"--sparse",
     20 	"--times",
     21 }
     22 
     23 func Rsync(dst *internal.URL, src *internal.URL) error {
     24 	src2 := *src
     25 	if !strings.HasSuffix(src2.Path, "/.") {
     26 		src2.Path = src2.Path + "/."
     27 	}
     28 
     29 	var stderr bytes.Buffer
     30 
     31 	args := append(rsyncOpts, src2.String(), dst.String())
     32 	cmd := exec.Command("rsync", args...)
     33 	cmd.Stderr = &stderr
     34 
     35 	err := cmd.Run()
     36 	if err != nil {
     37 		return errors.New(stderr.String())
     38 	}
     39 
     40 	return nil
     41 }