From 68c1bf6633d3e6219211e11c25435dffb4b6e9d5 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Sat, 22 Feb 2014 00:51:26 +0100 Subject: [PATCH 1/2] preserve ownership and permissions of existing file Signed-off-by: Steven Armstrong --- cdist/conf/type/__line/gencode-remote | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__line/gencode-remote b/cdist/conf/type/__line/gencode-remote index 1fadf454..1ac1ad13 100755 --- a/cdist/conf/type/__line/gencode-remote +++ b/cdist/conf/type/__line/gencode-remote @@ -1,6 +1,7 @@ #!/bin/sh # # 2012 Nico Schottelius (nico-cdist at schottelius.org) +# 2014 Steven Armstrong (steven-cdist at armstrong.cc) # # This file is part of cdist. # @@ -74,8 +75,13 @@ case "$state_should" in fi cat << eof -tmp=\$(mktemp) -grep -v $greparg '$regex' '$file' > \$tmp && cat "\$tmp" > '$file' && rm -f "\$tmp" +tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX) +# preserve ownership and permissions of existing file +if [ -f "$file" ]; then + cp -p "$file" "\$tmpfile" +fi +grep -v $greparg '$regex' '$file' > \$tmpfile +mv -f "\$tmpfile" "$file" eof ;; *) From 2fdff153d6f1c78693f7e49a9baa2b43cc668061 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Sat, 22 Feb 2014 00:51:54 +0100 Subject: [PATCH 2/2] dont fail if result is empty file Signed-off-by: Steven Armstrong --- cdist/conf/type/__line/gencode-remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__line/gencode-remote b/cdist/conf/type/__line/gencode-remote index 1ac1ad13..f73444e3 100755 --- a/cdist/conf/type/__line/gencode-remote +++ b/cdist/conf/type/__line/gencode-remote @@ -80,7 +80,7 @@ tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX) if [ -f "$file" ]; then cp -p "$file" "\$tmpfile" fi -grep -v $greparg '$regex' '$file' > \$tmpfile +grep -v $greparg '$regex' '$file' > \$tmpfile || true mv -f "\$tmpfile" "$file" eof ;;