summaryrefslogtreecommitdiff
path: root/portland/xdg-utils/scripts/xdg-utils-common.in
diff options
context:
space:
mode:
Diffstat (limited to 'portland/xdg-utils/scripts/xdg-utils-common.in')
-rw-r--r--portland/xdg-utils/scripts/xdg-utils-common.in55
1 files changed, 52 insertions, 3 deletions
diff --git a/portland/xdg-utils/scripts/xdg-utils-common.in b/portland/xdg-utils/scripts/xdg-utils-common.in
index 4204998..a8ab2dc 100644
--- a/portland/xdg-utils/scripts/xdg-utils-common.in
+++ b/portland/xdg-utils/scripts/xdg-utils-common.in
@@ -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"