mode and message handling now like __file type

This commit is contained in:
Daniel Heule 2014-01-08 13:10:46 +01:00
parent 3e398b233b
commit afb06b729e

View file

@ -56,15 +56,18 @@ get_current_value() {
} }
set_group() { set_group() {
echo chgrp $recursive \"$1\" \"$destination\" echo chgrp $recursive \"$1\" \"$destination\"
echo chgrp $recursive $1 >> "$__messages_out"
} }
set_owner() { set_owner() {
echo chown $recursive \"$1\" \"$destination\" echo chown $recursive \"$1\" \"$destination\"
echo chown $recursive $1 >> "$__messages_out"
} }
set_mode() { set_mode() {
echo chmod $recursive \"$1\" \"$destination\" echo chmod $recursive \"$1\" \"$destination\"
echo chmod $recursive $1 >> "$__messages_out"
} }
case "$state_should" in case "$state_should" in
@ -77,6 +80,7 @@ case "$state_should" in
rm -f "$destination" rm -f "$destination"
mkdir $mkdiropt "$destination" mkdir $mkdiropt "$destination"
DONE DONE
echo "remove non directory" >> "$__messages_out"
fi fi
# Note: Mode - needs to happen last as a chown/chgrp can alter mode by # Note: Mode - needs to happen last as a chown/chgrp can alter mode by
@ -85,12 +89,12 @@ DONE
if [ -f "$__object/parameter/$attribute" ]; then if [ -f "$__object/parameter/$attribute" ]; then
value_should="$(cat "$__object/parameter/$attribute")" value_should="$(cat "$__object/parameter/$attribute")"
value_is="$(get_current_value "$attribute" "$value_should")" value_is="$(get_current_value "$attribute" "$value_should")"
# the compare isn't correct when eg 0700 = 700 so we prefix the value_is to 4 chars
if [ "$attribute" = "mode" ] && [ ${#value_should} != ${#value_is} ]; then # change 0xxx format to xxx format => same as stat returns
if [ ${#value_is} = 3 ]; then if [ "$attribute" = mode ]; then
value_is=0${value_is} value_should="$(echo $value_should | sed 's/^0\(...\)/\1/')"
fi
fi fi
if [ "$set_attributes" = 1 ] || [ "$value_should" != "$value_is" ]; then if [ "$set_attributes" = 1 ] || [ "$value_should" != "$value_is" ]; then
"set_$attribute" "$value_should" "set_$attribute" "$value_should"
fi fi
@ -98,9 +102,10 @@ DONE
done done
;; ;;
absent) absent)
if [ "$type" = "directory" ]; then if [ "$type" = "directory" ]; then
echo rm -rf \"$destination\" echo rm -rf \"$destination\"
fi echo remove >> "$__messages_out"
fi
;; ;;
*) *)
echo "Unknown state: $state_should" >&2 echo "Unknown state: $state_should" >&2