From 9e207da19390794dd67ca4f6842976886a6db7cd Mon Sep 17 00:00:00 2001 From: Damir Dzeko Date: Mon, 21 Mar 2005 10:38:56 +0000 Subject: [PATCH] r13: functions.sh: - cp_safe_file_replace new-file target-file (new function) * function places new-file in place of target-file preserving original modes (or just renames new-file to target-file) - cp_check_and_sed: * utilizes this new cp_safe_file_replace function --- functions.sh | 19 +++++++++++++++---- test/test-file | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/functions.sh b/functions.sh index 13429de..e625d51 100644 --- a/functions.sh +++ b/functions.sh @@ -163,10 +163,8 @@ cp_check_and_sed() { egrep -q "$s" "$i" || continue [ -h "$i" ] && i=$(readlink -f "$i") sed "$sedcmd" "$i" > "$i.dpkg-tmp" - if ! cmp -s "$i" "$i.dpkg-tmp"; then - chown --reference "$i" "$i.dpkg-tmp" - chmod --reference "$i" "$i.dpkg-tmp" - mv "$i.dpkg-tmp" "$i" + if ! cmp -s "$i" "$i.dpkg-tmp" 2>&1 >/dev/null; then + cp_safe_file_replace "$i.dpkg-tmp" "$i" else rm "$i.dpkg-tmp" fi @@ -220,3 +218,16 @@ ${CP_NOTICE}----------" sleep 1 fi } + +# by ddzeko, Mon, 21 Mar 2005 11:31:59 +0100 +cp_safe_file_replace () { + [ "$CP_SCRIPT_DEBUG" ] && set -vx + local new old + new=$1 + old=$2 + if [ -e "$old" ]; then + chown --reference "$old" "$new" + chmod --reference "$old" "$new" + fi + mv "$new" "$old" +} diff --git a/test/test-file b/test/test-file index 1e6e4b7..be1b37b 100644 --- a/test/test-file +++ b/test/test-file @@ -26,4 +26,4 @@ string after the package name # Begin update by CARNet package broken2 -It's the end of the file and guess what? This line does not end with \n +It's the end of the file and guess what? This line does not end with \n \ No newline at end of file -- 1.7.10.4