bugfix, if file was absent and type is now tested on openwrt

This commit is contained in:
Daniel Heule 2014-03-11 21:05:31 +01:00
parent fa55cd7d3b
commit 38c3d551ba
3 changed files with 17 additions and 2 deletions

View File

@ -24,6 +24,12 @@ export key="$(cat "$__object/parameter/key" 2>/dev/null \
export state="$(cat "$__object/parameter/state" 2>/dev/null \ export state="$(cat "$__object/parameter/state" 2>/dev/null \
|| echo "present")" || echo "present")"
file="$(cat "$__object/parameter/file")" file="$(cat "$__object/parameter/file")"
if [ ! -f "$file" ]; then
echo "nosuchfile"
exit
fi
export delimiter="$(cat "$__object/parameter/delimiter")" export delimiter="$(cat "$__object/parameter/delimiter")"
export value="$(cat "$__object/parameter/value" 2>/dev/null \ export value="$(cat "$__object/parameter/value" 2>/dev/null \
|| echo "__CDIST_NOTSET__")" || echo "__CDIST_NOTSET__")"

View File

@ -44,7 +44,7 @@ fi
case "$state_should" in case "$state_should" in
absent) absent)
case "$state_is" in case "$state_is" in
absent) absent|nosuchfile)
# nothing to do # nothing to do
;; ;;
wrongformat|wrongvalue|present) wrongformat|wrongvalue|present)
@ -58,6 +58,9 @@ case "$state_should" in
;; ;;
present) present)
case "$state_is" in case "$state_is" in
nosuchfile)
echo created >> "$__messages_out"
;;
absent) absent)
echo inserted >> "$__messages_out" echo inserted >> "$__messages_out"
;; ;;
@ -104,7 +107,11 @@ export exact_delimiter="$exact_delimiter"
tmpfile=\$(mktemp "${file}.cdist.XXXXXXXXXX") tmpfile=\$(mktemp "${file}.cdist.XXXXXXXXXX")
# preserve ownership and permissions by copying existing file over tmpfile # preserve ownership and permissions by copying existing file over tmpfile
cp -p "$file" "\$tmpfile" if [ -f "$file" ]; then
cp -p "$file" "\$tmpfile"
else
touch "$file"
fi
awk -f - "$file" >"\$tmpfile" <<"AWK_EOF" awk -f - "$file" >"\$tmpfile" <<"AWK_EOF"
BEGIN { BEGIN {
# import variables in a secure way .. # import variables in a secure way ..

View File

@ -53,6 +53,8 @@ inserted::
A new line was inserted A new line was inserted
changed:: changed::
An existing line was changed An existing line was changed
created::
A new line was inserted in a new file
EXAMPLES EXAMPLES