From 175660872092958b9e0a30c2de0dd06e8ce440c9 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 23 Mar 2011 13:33:26 +0100 Subject: [PATCH] in theory finish new algorithm to allow same objects Signed-off-by: Nico Schottelius --- bin/cdist-config | 7 ++++++- bin/cdist-type-emulator | 33 ++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/bin/cdist-config b/bin/cdist-config index 21b797bb..e5dc46c0 100755 --- a/bin/cdist-config +++ b/bin/cdist-config @@ -192,7 +192,12 @@ __cdist_object_code_finished() __cdist_object_dir() { - echo "${__cdist_out_object_dir}/$1/${__cdist_name_dot_cdist}" + echo "$(__cdist_object_dir_base "$1")/${__cdist_name_dot_cdist}" +} + +__cdist_object_dir_base() +{ + echo "${__cdist_out_object_dir}/$1" } diff --git a/bin/cdist-type-emulator b/bin/cdist-type-emulator index 8451ec9d..cf2bc418 100755 --- a/bin/cdist-type-emulator +++ b/bin/cdist-type-emulator @@ -77,7 +77,6 @@ __cdist_object_dir="$(__cdist_object_dir "$__cdist_object_self")" mkdir -p "${__cdist_object_dir}" __cdist_object_source_add "${__cdist_object_dir}" - # Record parameter __cdist_parameter_dir="$(__cdist_object_parameter_dir "$__cdist_object_self")" mkdir -p "${__cdist_parameter_dir}" @@ -152,19 +151,43 @@ exit 1 # Save original destination __cdist_out_object_dir="$__cdist_out_object_dir_orig" -__cdist_object_destination_dir="$(__cdist_object_dir "$__cdist_object_self")" +__cdist_new_object_dir="$(__cdist_object_dir "$__cdist_object_self")" # # If the object already exists and is exactly the same, merge it. Otherwise fail. # if [ -e "${__cdist_new_object_dir}" ]; then - source="$(__cdist_object_source "${__cdist_new_object_dir}")" - __cdist_exit_err "${__cdist_object} already exists (source: $source)" - + # Allow diff to fail + set +e + diff -ru "${__cdist_object_dir}" "${__cdist_new_object_dir}" \ + > "$__cdist_tmp_file"; ret=$? + set -e + + if [ "$ret" != 0 ]; then + # Go to standard error + exec >&2 + echo "${__cdist_object_self} already exists differently." + echo "Recorded source(s):" + __cdist_object_source "${__cdist_new_object_dir}" + echo "Differences:" + cat "$__cdist_tmp_file" + __cdist_exit_err "Aborting due to object conflict." + fi + # Add ourselves, if we're compatible + __cdist_object_source_add "${__cdist_new_object_dir}" +else + # + # Move object into tree: + # Create full path minus .cdist and move .cdist + # + __cdist_new_object_base_dir="$(__cdist_object_base_dir "$__cdist_object_self")" + mkdir -p "$__cdist_new_object_base_dir" + mv "$__cdist_object_dir" "$__cdist_new_object_base_dir" fi +exit 0 # --------------------------------------------------------------------------------