diff options
author | Waldo Bastian <waldo.bastian@intel.com> | 2006-07-31 15:57:38 +0000 |
---|---|---|
committer | Waldo Bastian <waldo.bastian@intel.com> | 2006-07-31 15:57:38 +0000 |
commit | 9a875fb5629858b019eab4b571e84e326e8a8eed (patch) | |
tree | 0514be93ce988a56d35e7e37a95710db1ff0ea42 /portland | |
parent | 019013c4559c2f278cd7eb29a090759ea4bb4739 (diff) |
Use check_input_file to check for read permission
Diffstat (limited to 'portland')
-rw-r--r-- | portland/xdg-utils/scripts/desc/xdg-mime.xml | 9 | ||||
-rw-r--r-- | portland/xdg-utils/scripts/html/xdg-mime.html | 3 | ||||
-rw-r--r-- | portland/xdg-utils/scripts/man/xdg-mime.1 | 5 | ||||
-rwxr-xr-x | portland/xdg-utils/scripts/xdg-mime | 66 | ||||
-rwxr-xr-x | portland/xdg-utils/scripts/xdg-mime.in | 11 |
5 files changed, 76 insertions, 18 deletions
diff --git a/portland/xdg-utils/scripts/desc/xdg-mime.xml b/portland/xdg-utils/scripts/desc/xdg-mime.xml index 1fdf876..5de877d 100644 --- a/portland/xdg-utils/scripts/desc/xdg-mime.xml +++ b/portland/xdg-utils/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/portland/xdg-utils/scripts/html/xdg-mime.html b/portland/xdg-utils/scripts/html/xdg-mime.html index 7cdc636..e3637f6 100644 --- a/portland/xdg-utils/scripts/html/xdg-mime.html +++ b/portland/xdg-utils/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/portland/xdg-utils/scripts/man/xdg-mime.1 b/portland/xdg-utils/scripts/man/xdg-mime.1 index d25403e..99451c4 100644 --- a/portland/xdg-utils/scripts/man/xdg-mime.1 +++ b/portland/xdg-utils/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/portland/xdg-utils/scripts/xdg-mime b/portland/xdg-utils/scripts/xdg-mime index 867c9a7..957cd10 100755 --- a/portland/xdg-utils/scripts/xdg-mime +++ b/portland/xdg-utils/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/portland/xdg-utils/scripts/xdg-mime.in b/portland/xdg-utils/scripts/xdg-mime.in index 5c9063a..28d1dbb 100755 --- a/portland/xdg-utils/scripts/xdg-mime.in +++ b/portland/xdg-utils/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 |