preserve ownership and permissions of existing file

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2014-02-22 00:51:26 +01:00
parent 9c6defe17c
commit 68c1bf6633

View file

@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
# #
# 2012 Nico Schottelius (nico-cdist at schottelius.org) # 2012 Nico Schottelius (nico-cdist at schottelius.org)
# 2014 Steven Armstrong (steven-cdist at armstrong.cc)
# #
# This file is part of cdist. # This file is part of cdist.
# #
@ -74,8 +75,13 @@ case "$state_should" in
fi fi
cat << eof cat << eof
tmp=\$(mktemp) tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX)
grep -v $greparg '$regex' '$file' > \$tmp && cat "\$tmp" > '$file' && rm -f "\$tmp" # 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 eof
;; ;;
*) *)