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 \
|| echo "present")"
file="$(cat "$__object/parameter/file")"
if [ ! -f "$file" ]; then
echo "nosuchfile"
exit
fi
export delimiter="$(cat "$__object/parameter/delimiter")"
export value="$(cat "$__object/parameter/value" 2>/dev/null \
|| echo "__CDIST_NOTSET__")"

View file

@ -44,7 +44,7 @@ fi
case "$state_should" in
absent)
case "$state_is" in
absent)
absent|nosuchfile)
# nothing to do
;;
wrongformat|wrongvalue|present)
@ -58,6 +58,9 @@ case "$state_should" in
;;
present)
case "$state_is" in
nosuchfile)
echo created >> "$__messages_out"
;;
absent)
echo inserted >> "$__messages_out"
;;
@ -104,7 +107,11 @@ export exact_delimiter="$exact_delimiter"
tmpfile=\$(mktemp "${file}.cdist.XXXXXXXXXX")
# 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"
BEGIN {
# import variables in a secure way ..

View file

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