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:35:40 -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,70 @@ exit_failure_operation_failed() exit 4 } +#------------------------------------------------------------- +# Exit script on failure to find a specified file + +exit_failure_file_does_not_exist() +{ + if [ $# -gt 0 ]; then + echo "@NAME@: $@" >&2 + echo "File '$1' does not exist" >&2 + fi + + exit 5 +} + +#------------------------------------------------------------ +# Exit script on insufficient permission to read a specified file + +exit_failure_file_permission_read() +{ + if [ $# -gt 0 ]; then + echo "@NAME@: $@" >&2 + echo "No permission to read file '$1'" >&2 + fi + + exit 6 +} + +#------------------------------------------------------------ +# Exit script on insufficient permission to read a specified file + +exit_failure_file_permission_write() +{ + if [ $# -gt 0 ]; then + echo "@NAME@: $@" >&2 + echo "No permission to write to file '$1'" >&2 + fi + + exit 6 +} + +check_input_file() +{ + if [ ! -e $1 ]; then + exit_failure_file_does_not_exist $1 + fi + if [ ! -r $1 ]; then + exit_failure_file_permission_read $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 $1 + fi + else + DIR=`dirname $1` + if [ ! -w $DIR ]; then + exit_failure_file_permission_write $1 + fi + fi +} #---------------------------------------- # Checks for shared commands, e.g. --help @@ -91,7 +155,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 +175,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"