From fcfd2d0a3c6410f73b73cd897f5dd09526868f35 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 26 Nov 2013 16:30:03 +0100 Subject: [PATCH] refactor so that there is no interaction between code-local and code-remote Signed-off-by: Steven Armstrong --- cdist/conf/type/__file/gencode-local | 17 +++++++++++++++-- cdist/conf/type/__file/gencode-remote | 18 +----------------- cdist/config.py | 4 +++- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/cdist/conf/type/__file/gencode-local b/cdist/conf/type/__file/gencode-local index 80a2bc20..a9eb6b10 100755 --- a/cdist/conf/type/__file/gencode-local +++ b/cdist/conf/type/__file/gencode-local @@ -53,11 +53,24 @@ if [ "$state_should" = "present" -o "$state_should" = "exists" ]; then fi fi if [ "$create_file" -o "$upload_file" ]; then + # tell gencode-remote that we created or uploaded a file and that it must + # set all attributes no matter what the explorer retreived mkdir "$__object/files" + touch "$__object/files/set-attributes" + + # upload file to temp location tempfile_template="${destination}.cdist.XXXXXXXXXX" - echo "$__remote_exec ${__target_host} \"mktemp $tempfile_template\" > \"$__object/files/destination_upload\"" + cat << DONE +destination_upload="\$($__remote_exec $__target_host "mktemp $tempfile_template")" +DONE if [ "$upload_file" ]; then - echo "$__remote_copy $source ${__target_host}:\$(cat \"$__object/files/destination_upload\")" + cat << DONE +$__remote_copy $source ${__target_host}:\$destination_upload +DONE fi +# move uploaded file into place +cat << DONE +$__remote_exec $__target_host "rm -rf \"$destination\"; mv \"\$destination_upload\" \"$destination\"" +DONE fi fi diff --git a/cdist/conf/type/__file/gencode-remote b/cdist/conf/type/__file/gencode-remote index 2e7ca633..e80d5fae 100755 --- a/cdist/conf/type/__file/gencode-remote +++ b/cdist/conf/type/__file/gencode-remote @@ -57,29 +57,13 @@ set_mode() { set_attributes= case "$state_should" in present|exists) - if [ -f "$__object/files/destination_upload" ]; then - # we uploaded a file, move it into place and set all attributes - destination_upload="$(cat "$__object/files/destination_upload")" - set_attributes=1 - if [ "$type" = "directory" ]; then - # our destination is currently a directory, delete it - cat << DONE -rm -rf "$destination" -DONE - fi - # move our upload into place - cat << DONE -mv "$destination_upload" "$destination" -DONE - fi - # Note: Mode - needs to happen last as a chown/chgrp can alter mode by # clearing S_ISUID and S_ISGID bits (see chown(2)) for attribute in group owner mode; do if [ -f "$__object/parameter/$attribute" ]; then value_should="$(cat "$__object/parameter/$attribute")" value_is="$(get_current_value "$attribute" "$value_should")" - if [ "$set_attributes" -o "$value_should" != "$value_is" ]; then + if [ -f "$__object/files/set-attributes" -o "$value_should" != "$value_is" ]; then "set_$attribute" "$value_should" fi fi diff --git a/cdist/config.py b/cdist/config.py index 7e003835..3f8a7fc6 100644 --- a/cdist/config.py +++ b/cdist/config.py @@ -249,7 +249,7 @@ class Config(object): cdist_type = cdist_object.cdist_type # Generate - self.log.info("Generating and executing code for %s" % (cdist_object.name)) + self.log.info("Generating code for %s" % (cdist_object.name)) cdist_object.code_local = self.code.run_gencode_local(cdist_object) cdist_object.code_remote = self.code.run_gencode_remote(cdist_object) if cdist_object.code_local or cdist_object.code_remote: @@ -257,6 +257,8 @@ class Config(object): # Execute if not self.dry_run: + if cdist_object.code_local or cdist_object.code_remote: + self.log.info("Executing code for %s" % (cdist_object.name)) if cdist_object.code_local: self.code.run_code_local(cdist_object) if cdist_object.code_remote: