From 087ad206db4ef25eff2c21c3d6e06194f0e217ee Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 24 Feb 2014 15:52:53 +0000 Subject: Prevent patching when 'vu == v2' in 'baserock-system-config-sync'. When vu == v2, the script tried to reverse the patch. Now this won't happen again. Also added '-f' flag calling 'patch' to prevent also reverse patching. --- .../baserock-system-config-sync | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/baserock-system-config-sync/baserock-system-config-sync b/baserock-system-config-sync/baserock-system-config-sync index a093b15..e297197 100755 --- a/baserock-system-config-sync/baserock-system-config-sync +++ b/baserock-system-config-sync/baserock-system-config-sync @@ -134,6 +134,7 @@ merge_regular_file() { v1_exists=$(test -f "$v1" && echo exists || echo none) vu_exists=$(test -f "$vu" && echo exists || echo none) v2_exists=$(test -f "$v2" && echo exists || echo none) + case "$v1_exists $vu_exists $v2_exists" in 'exists none none') cp -a "$v1" "$vt" @@ -152,16 +153,24 @@ merge_regular_file() { ;; 'none exists exists') cp -a "$v2" "$vt" - if ! (diff -u "$v2" --label="$v2" "$vu" --label="$vu" | patch "$vt" -t); then - cp -a "$v2" "$vt" # merge failed, use v2 - # 'patch' creates a file '.rej' with the diff that did not apply + + # If v2 == vu, then use v2 + if ! cmp -s "$v2" "$vu"; then + if ! (diff -u "$v2" --label="$v2" "$vu" --label="$vu" | patch "$vt" -f); then + cp -a "$v2" "$vt" # merge failed, use v2 + # 'patch' creates a file '.rej' with the diff that did not apply + fi fi ;; 'exists exists exists') cp -a "$v2" "$vt" - if ! (diff -u "$v1" --label="$v1" "$vu" --label="$vu" | patch "$vt" -t); then - cp -a "$v2" "$vt" # merge failed, use v2 - # 'patch' creates a file '.rej' with the diff that did not apply + + # If v2 == vu, then use v2 + if ! cmp -s "$v2" "$vu"; then + if ! (diff -u "$v1" --label="$v1" "$vu" --label="$vu" | patch "$vt" -f); then + cp -a "$v2" "$vt" # merge failed, use v2 + # 'patch' creates a file '.rej' with the diff that did not apply + fi fi ;; *) -- cgit v1.2.1