Index: xdg-utils-common.in =================================================================== RCS file: /cvs/portland/portland/xdg-utils/scripts/xdg-utils-common.in,v retrieving revision 1.12 diff -u -3 -p -r1.12 xdg-utils-common.in --- xdg-utils-common.in 25 Jul 2006 00:44:02 -0000 1.12 +++ xdg-utils-common.in 28 Jul 2006 20:58:17 -0000 @@ -36,7 +36,7 @@ exit_failure_syntax() echo "Try '@NAME@ --help' for more information." >&2 else usage - echo "Use 'man @NAME@' or '@NAME@ --manual' for additional info." + echo "Use 'man @NAME@' or '@NAME@ --manual' for additional info." fi exit 1 @@ -78,6 +78,55 @@ exit_failure_operation_failed() exit 4 } +#------------------------------------------------------------ +# Exit script on insufficient permission to read a specified file + +exit_failure_file_permission_read() +{ + if [ $# -gt 0 ]; then + echo "@NAME@: $@" >&2 + fi + + exit 5 +} + +#------------------------------------------------------------ +# Exit script on insufficient permission to read a specified file + +exit_failure_file_permission_write() +{ + if [ $# -gt 0 ]; then + echo "@NAME@: $@" >&2 + fi + + exit 6 +} + +check_input_file() +{ + if [ ! -e "$1" ]; then + exit_failure_file_missing "file '$1' does not exist" + fi + if [ ! -r "$1" ]; then + exit_failure_file_permission_read "no permission to read file '$1'" + fi +} + +check_output_file() +{ + # if the file exists, check if it is writeable + # if it does not exists, check if we are allowed to write on the directory + if [ -e "$1" ]; then + if [ ! -w "$1" ]; then + exit_failure_file_permission_write "no permission to write to file '$1'" + fi + else + DIR=`dirname "$1"` + if [ ! -w "$DIR" -o ! -x "$DIR" ]; then + exit_failure_file_permission_write "no permission to create file '$1'" + fi + fi +} #---------------------------------------- # Checks for shared commands, e.g. --help @@ -91,7 +140,7 @@ check_common_commands() case "$parm" in --help) usage - echo "Use 'man @NAME@' or '@NAME@ --manual' for additional info." + echo "Use 'man @NAME@' or '@NAME@ --manual' for additional info." exit_success ;; @@ -111,7 +160,7 @@ check_common_commands() check_common_commands "$@" if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then # Be silent - xdg_redirect_output=" > /dev/null 2> /dev/null" + xdg_redirect_output=" > /dev/null 2> /dev/null" else # All output to stderr xdg_redirect_output=" >&2"