From 5edf39f1114be85fe3b8d1b772f5625e3177a14f Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 29 May 2012 11:02:23 +0200 Subject: [PATCH] no special case for rsync in core. handle implementation specific details in remote-copy script instead Signed-off-by: Steven Armstrong --- lib/cdist/exec/remote.py | 7 +------ other/examples/remote/rsync/copy | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/cdist/exec/remote.py b/lib/cdist/exec/remote.py index fb90939d..487beea3 100644 --- a/lib/cdist/exec/remote.py +++ b/lib/cdist/exec/remote.py @@ -77,12 +77,7 @@ class Remote(object): self.log.debug("Remote transfer: %s -> %s", source, destination) self.rmdir(destination) command = self._copy.split() - # support rsync by appending a "/" to the source if it's a directory - if os.path.isdir(source): - command.extend(["-r", source + "/", self.target_host + ":" + destination]) - else: - command.extend(["-r", source, self.target_host + ":" + destination]) - + command.extend(["-r", source, self.target_host + ":" + destination]) self._run_command(command) def run_script(self, script, env=None, return_output=False): diff --git a/other/examples/remote/rsync/copy b/other/examples/remote/rsync/copy index f6b93c5c..96d3f3de 100755 --- a/other/examples/remote/rsync/copy +++ b/other/examples/remote/rsync/copy @@ -24,7 +24,24 @@ # at /etc/passwd~cdist. # # Usage: -# __remote_copy="/path/to/this/script" cdist config target_host +# cdist config --remote-copy /path/to/this/script target_host # +# second last argument is the source +source_index=$(($#-1)) +index=0 +for arg in $@; do + if [ $index -eq 0 ]; then + # reset $@ + set -- + fi + index=$((index+=1)) + if [ $index -eq $source_index -a -d "$arg" ]; then + echo "directory: $arg" | logger + # if the source is a directory, it has to end with "/" for rsync to do the right thing + arg="${arg%/}/" + fi + set -- "$@" "$arg" +done + rsync --backup --suffix=~cdist -e 'ssh -o User=root' $@