rsync is a wrapper for the rsync command which will respect RunWrapper.
(args ...string)
| 29 | |
| 30 | // rsync is a wrapper for the rsync command which will respect RunWrapper. |
| 31 | func rsync(args ...string) (string, error) { |
| 32 | if len(args) < 2 { |
| 33 | return "", errors.New("rsync call expects a minimum of two arguments (source and destination)") |
| 34 | } |
| 35 | |
| 36 | // Setup the command. |
| 37 | cmd := exec.Command("rsync", args...) |
| 38 | var stderr bytes.Buffer |
| 39 | cmd.Stderr = &stderr |
| 40 | var stdout bytes.Buffer |
| 41 | cmd.Stdout = &stdout |
| 42 | |
| 43 | // Call the wrapper if defined. |
| 44 | if RunWrapper != nil { |
| 45 | source := args[len(args)-2] |
| 46 | destination := args[len(args)-1] |
| 47 | |
| 48 | cleanup, err := RunWrapper(cmd, source, destination) |
| 49 | if err != nil { |
| 50 | return "", err |
| 51 | } |
| 52 | |
| 53 | defer cleanup() |
| 54 | } |
| 55 | |
| 56 | // Run the command. |
| 57 | err := cmd.Run() |
| 58 | if err != nil { |
| 59 | return stdout.String(), subprocess.NewRunError("rsync", args, err, &stdout, &stderr) |
| 60 | } |
| 61 | |
| 62 | return stdout.String(), nil |
| 63 | } |
| 64 | |
| 65 | // LocalCopy copies a directory using rsync (with the --devices option). |
| 66 | func LocalCopy(source string, dest string, bwlimit string, xattrs bool, rsyncArgs ...string) (string, error) { |
no test coverage detected
searching dependent graphs…