From d71ff3eaa4a55b32659e165efe4b78149ef240cb Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 19 Feb 2014 13:03:39 +0000 Subject: Modify the way to use 'patch' in 'baserock-system-config-sync'. baserock-sytem-config-sync: Changes here are caused by a bug found in GNU patch managing the permissions of the files when using the patch command like: patch -t -o To reproduce the bug: echo foo > file1 echo bar > file2 diff -u file1 file2 | patch 1 -t -o file3 ls -l You can check that the permissions of 'file3' are different than the permissions of 'file1' or 'file2'. To avoid the bug, this patch changes the way we are using patch, using it as following: patch -t Since the output file is not specified, the output file will be the file in which we want to apply the patch. And due we cannot specify the output file, we are copying the file to the destination directory, and then applying the patch there. As a consequence of changing the way of using patch, now 'patch' generates an extra file when patching fails. This file is added in the test suite also in this commit. --- baserock-system-config-sync/baserock-system-config-sync | 8 ++++++-- .../upgrades.out/systems/version2/run/etc/file7.orig | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tests/bscs-merge.pass/upgrades.out/systems/version2/run/etc/file7.orig diff --git a/baserock-system-config-sync/baserock-system-config-sync b/baserock-system-config-sync/baserock-system-config-sync index cb5984d..a093b15 100755 --- a/baserock-system-config-sync/baserock-system-config-sync +++ b/baserock-system-config-sync/baserock-system-config-sync @@ -151,13 +151,17 @@ merge_regular_file() { cp -a "$vu" "$vt" ;; 'none exists exists') - if ! (diff -u "$v2" --label="$v2" "$vu" --label="$vu" | patch "$v2" -t -o "$vt"); then + 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 fi ;; 'exists exists exists') - if ! (diff -u "$v1" --label="$v1" "$vu" --label="$vu" | patch "$v2" -t -o "$vt"); then + 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 fi ;; *) diff --git a/tests/bscs-merge.pass/upgrades.out/systems/version2/run/etc/file7.orig b/tests/bscs-merge.pass/upgrades.out/systems/version2/run/etc/file7.orig new file mode 100644 index 0000000..93c46eb --- /dev/null +++ b/tests/bscs-merge.pass/upgrades.out/systems/version2/run/etc/file7.orig @@ -0,0 +1,2 @@ +whereami=v1,vu,v2 +version=v2 -- cgit v1.2.1