diff options
-rw-r--r-- | scripts/desc/xdg-mime.xml | 9 | ||||
-rw-r--r-- | scripts/html/xdg-mime.html | 3 | ||||
-rw-r--r-- | scripts/man/xdg-mime.1 | 5 | ||||
-rwxr-xr-x | scripts/xdg-mime | 66 | ||||
-rwxr-xr-x | scripts/xdg-mime.in | 11 |
5 files changed, 76 insertions, 18 deletions
diff --git a/scripts/desc/xdg-mime.xml b/scripts/desc/xdg-mime.xml index 1fdf876..5de877d 100644 --- a/scripts/desc/xdg-mime.xml +++ b/scripts/desc/xdg-mime.xml @@ -288,6 +288,15 @@ and adding descriptions for new file types</refpurpose> </simpara> </listitem> </varlistentry> + <varlistentry> + <term><option>5</option></term> + <listitem> + <simpara> + No permission to read one of the files passed on the command + line. + </simpara> + </listitem> + </varlistentry> </variablelist> </refsect1> <refsect1 id="seealso"> diff --git a/scripts/html/xdg-mime.html b/scripts/html/xdg-mime.html index 7cdc636..e3637f6 100644 --- a/scripts/html/xdg-mime.html +++ b/scripts/html/xdg-mime.html @@ -84,6 +84,9 @@ and adding descriptions for new file types</p></div><div class="refsynopsisdiv"> A required tool could not be found. </dd><dt><span class="term"><code class="option">4</code></span></dt><dd> The action failed. + </dd><dt><span class="term"><code class="option">5</code></span></dt><dd> + No permission to read one of the files passed on the command + line. </dd></dl></div></div><div class="refsect1" lang="en"><a name="seealso"></a><h2>See Also</h2><p><span class="citerefentry"><span class="refentrytitle">xdg-icon-resource</span>(1)</span>, <span class="citerefentry"><span class="refentrytitle">xdg-desktop-menu</span>(1)</span> </p></div><div class="refsect1" lang="en"><a name="examples"></a><h2>Examples</h2><p> diff --git a/scripts/man/xdg-mime.1 b/scripts/man/xdg-mime.1 index d25403e..99451c4 100644 --- a/scripts/man/xdg-mime.1 +++ b/scripts/man/xdg-mime.1 @@ -2,7 +2,7 @@ .\" It was generated using the DocBook XSL Stylesheets (version 1.69.1). .\" Instead of manually editing it, you probably should edit the DocBook XML .\" source for it and then use the DocBook XSL Stylesheets to regenerate it. -.TH "XDG\-MIME" "1" "07/28/2006" "This is release 0.5 of the xdg\-mime Manu" "" +.TH "XDG\-MIME" "1" "07/31/2006" "This is release 0.5 of the xdg\-mime Manu" "" .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) @@ -118,6 +118,9 @@ A required tool could not be found. .TP \fB4\fR The action failed. +.TP +\fB5\fR +No permission to read one of the files passed on the command line. .SH "SEE ALSO" .PP \fBxdg\-icon\-resource\fR(1), diff --git a/scripts/xdg-mime b/scripts/xdg-mime index 867c9a7..957cd10 100755 --- a/scripts/xdg-mime +++ b/scripts/xdg-mime @@ -147,6 +147,8 @@ failure. The following failure codes can be returned: A required tool could not be found. 4 The action failed. +5 + No permission to read one of the files passed on the command line. See Also @@ -246,7 +248,7 @@ exit_failure_syntax() echo "Try 'xdg-mime --help' for more information." >&2 else usage - echo "Use 'man xdg-mime' or 'xdg-mime --manual' for additional info." + echo "Use 'man xdg-mime' or 'xdg-mime --manual' for additional info." fi exit 1 @@ -288,6 +290,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 "xdg-mime: $@" >&2 + fi + + exit 5 +} + +#------------------------------------------------------------ +# Exit script on insufficient permission to read a specified file + +exit_failure_file_permission_write() +{ + if [ $# -gt 0 ]; then + echo "xdg-mime: $@" >&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 @@ -301,7 +352,7 @@ check_common_commands() case "$parm" in --help) usage - echo "Use 'man xdg-mime' or 'xdg-mime --manual' for additional info." + echo "Use 'man xdg-mime' or 'xdg-mime --manual' for additional info." exit_success ;; @@ -321,7 +372,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" @@ -582,9 +633,7 @@ case $1 in exit_failure_syntax "unexpected option '$filename'" ;; esac - if [ ! -f "$filename" ] ; then - exit_failure_file_missing "file '$filename' does not exist" - fi + check_input_file "$filename" ;; default) @@ -725,10 +774,9 @@ while [ $# -gt 0 ] ; do if [ -n "$filename" ] ; then exit_failure_syntax "unexpected argument '$parm'" fi - if [ ! -f "$parm" ] ; then - exit_failure_file_missing "file '$parm' does not exist" - fi + filename="$parm" + check_input_file "$filename" ;; esac done diff --git a/scripts/xdg-mime.in b/scripts/xdg-mime.in index 5c9063a..28d1dbb 100755 --- a/scripts/xdg-mime.in +++ b/scripts/xdg-mime.in @@ -267,9 +267,7 @@ case $1 in exit_failure_syntax "unexpected option '$filename'" ;; esac - if [ ! -f "$filename" ] ; then - exit_failure_file_missing "file '$filename' does not exist" - fi + check_input_file "$filename" ;; default) @@ -350,8 +348,6 @@ if [ "$action" = "makedefault" ]; then fi if [ "$action" = "info" ]; then - check_input_file "$filename" - detectDE if [ x"$DE" = x"" ]; then @@ -412,10 +408,9 @@ while [ $# -gt 0 ] ; do if [ -n "$filename" ] ; then exit_failure_syntax "unexpected argument '$parm'" fi - if [ ! -f "$parm" ] ; then - exit_failure_file_missing "file '$parm' does not exist" - fi + filename="$parm" + check_input_file "$filename" ;; esac done |