diff options
author | Pedro Alvarez <pedro.alvarez@codethink.co.uk> | 2014-02-19 13:03:39 +0000 |
---|---|---|
committer | Pedro Alvarez <pedro.alvarez@codethink.co.uk> | 2014-02-20 15:42:06 +0000 |
commit | d71ff3eaa4a55b32659e165efe4b78149ef240cb (patch) | |
tree | 0d89f7495dd2704d28d9d090f261c352a2675e02 /baserock-system-config-sync | |
parent | f5723961ef7fc9c71222e8b45e0de39e7f15e90e (diff) | |
download | tbdiff-d71ff3eaa4a55b32659e165efe4b78149ef240cb.tar.gz |
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 <file_to_apply_patch> -t -o <output_file>
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 <file_to_apply_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.
Diffstat (limited to 'baserock-system-config-sync')
-rwxr-xr-x | baserock-system-config-sync/baserock-system-config-sync | 8 |
1 files changed, 6 insertions, 2 deletions
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 ;; *) |