forked from ungleich-public/cdist
Merge branch 'file/better-errors' into 'master'
[__file] Better errors analogous to __directory See merge request ungleich-public/cdist!854
This commit is contained in:
commit
4b24d886eb
2 changed files with 48 additions and 32 deletions
|
@ -31,12 +31,24 @@ if [ "$state_should" = "pre-exists" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$type" = "file" ]; then
|
case $type in
|
||||||
exit 0 # nothing to do
|
file)
|
||||||
else
|
# nothing to do
|
||||||
echo "File \"$destination\" does not exist"
|
exit 0
|
||||||
exit 1
|
;;
|
||||||
fi
|
none)
|
||||||
|
printf 'File "%s" does not exist\n' "$destination" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
directory|symlink)
|
||||||
|
printf 'File "%s" exists and is a %s, but should be a regular file\n' "$destination" "$type" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf 'File or directory "%s" is in an unknown state\n' "$destination" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
upload_file=
|
upload_file=
|
||||||
|
|
|
@ -55,37 +55,41 @@ set_owner() {
|
||||||
}
|
}
|
||||||
|
|
||||||
set_mode() {
|
set_mode() {
|
||||||
echo "chmod '$1' '$destination'"
|
echo "chmod '$1' '$destination'"
|
||||||
echo "chmod '$1'" >> "$__messages_out"
|
echo "chmod '$1'" >> "$__messages_out"
|
||||||
fire_onchange=1
|
fire_onchange=1
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$state_should" in
|
case "$state_should" in
|
||||||
present|exists|pre-exists)
|
present|exists)
|
||||||
# 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
|
||||||
# clearing S_ISUID and S_ISGID bits (see chown(2))
|
# clearing S_ISUID and S_ISGID bits (see chown(2))
|
||||||
for attribute in group owner mode; do
|
for attribute in group owner mode; do
|
||||||
if [ -f "$__object/parameter/$attribute" ]; then
|
if [ -f "$__object/parameter/$attribute" ]; then
|
||||||
value_should="$(cat "$__object/parameter/$attribute")"
|
value_should="$(cat "$__object/parameter/$attribute")"
|
||||||
|
|
||||||
# change 0xxx format to xxx format => same as stat returns
|
# change 0xxx format to xxx format => same as stat returns
|
||||||
if [ "$attribute" = mode ]; then
|
if [ "$attribute" = mode ]; then
|
||||||
value_should="$(echo "$value_should" | sed 's/^0\(...\)/\1/')"
|
value_should="$(echo "$value_should" | sed 's/^0\(...\)/\1/')"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
value_is="$(get_current_value "$attribute" "$value_should")"
|
value_is="$(get_current_value "$attribute" "$value_should")"
|
||||||
if [ -f "$__object/files/set-attributes" ] || [ "$value_should" != "$value_is" ]; then
|
if [ -f "$__object/files/set-attributes" ] || [ "$value_should" != "$value_is" ]; then
|
||||||
"set_$attribute" "$value_should"
|
"set_$attribute" "$value_should"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
if [ -f "$__object/files/set-attributes" ]; then
|
||||||
|
# set-attributes is created if file is created or uploaded in gencode-local
|
||||||
|
fire_onchange=1
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
if [ -f "$__object/files/set-attributes" ]; then
|
|
||||||
# set-attributes is created if file is created or uploaded in gencode-local
|
|
||||||
fire_onchange=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
pre-exists)
|
||||||
|
# pre-exists should never reach gencode-remote…
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
absent)
|
absent)
|
||||||
if [ "$type" = "file" ]; then
|
if [ "$type" = "file" ]; then
|
||||||
echo "rm -f '$destination'"
|
echo "rm -f '$destination'"
|
||||||
|
@ -101,7 +105,7 @@ case "$state_should" in
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ -f "$__object/parameter/onchange" ]; then
|
if [ -f "$__object/parameter/onchange" ]; then
|
||||||
if [ -n "$fire_onchange" ]; then
|
if [ -n "$fire_onchange" ]; then
|
||||||
cat "$__object/parameter/onchange"
|
cat "$__object/parameter/onchange"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue