Bug 7123 - xdg-mime has inconsistant output for error cases
Summary: xdg-mime has inconsistant output for error cases
Status: RESOLVED FIXED
Alias: None
Product: Portland
Classification: Unclassified
Component: xdg-utils (show other bugs)
Version: unspecified
Hardware: x86 (IA32) Linux (All)
: high normal
Assignee: Portland Integration Project
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 7011
  Show dependency treegraph
 
Reported: 2006-06-05 17:16 UTC by Tom Whipple
Modified: 2006-08-03 13:29 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
File check functions (2.86 KB, patch)
2006-07-28 13:38 UTC, Kevin Krammer
Details | Splinter Review
Improved patch (2.61 KB, patch)
2006-07-28 14:00 UTC, Kevin Krammer
Details | Splinter Review
Using check_input_file in xdg-mime (499 bytes, patch)
2006-07-28 14:01 UTC, Kevin Krammer
Details | Splinter Review

Description Tom Whipple 2006-06-05 17:16:05 UTC
Consider the following three error cases:

1. foo.bar does not exist. "xdg-mime --info foo.bar" does not print any result.
Exit value is 0. We would expect an error message and non-zero exit.

2. foo.bar is a zero byte readable file. "xdg-mime --info foo.bar" prints
"text/plain". Is this the expected default behavior? If so, it should be stated.

3. foo.bar is a zero byte file with permissions 000. "xdg-mime --info foo.bar"
prints "application/octet-stream". We would expect an error message and non-zero
exit.

Environment is SUSE 10.0, Gnome 2.12.0
Comment 1 Kevin Krammer 2006-06-06 00:33:56 UTC
Behavior on KDE3.5 is
1. prints application/octet-stream

2. prints application/x-zerosize

3. prints application/x-zerosize on the file from (2) and 
application/octet-stream on a file with size > 0

/usr/bin/file does

1. prints error exits with error code

2. prints application/x-empty

3. prints application/x-empty for the zero sized file and an error message for 
a file with length. Return value is 0 in both cases.

Comment 2 Bryce Harrington 2006-06-09 20:50:39 UTC
Presently, on gentoo kde 3.5.3, I get the following:

1.  Error code == 1, error msg "--info:  Invalid parameter/option"
2.  ditto
3.  ditto

Is this expected behavior?  
Comment 3 Waldo Bastian 2006-06-09 22:50:47 UTC
Syntax has changed, instead of "xdg-mime --info" use "xdg-mime query filetype"

1. Now returns with 2 --> "One of the files passed on the command line did not 
exist."

With regard to 2 and 3: There is no guarantee that results in different 
environments will be the same, is there a reason why the cases described 
should be treated as special case?

That said, we can do a check for 3 and return an error code for "file not 
readable"
Comment 4 Bryce Harrington 2006-06-10 00:03:47 UTC
Am I doing something wrong?  I get this on kde:

$ ./xdg-mime query foo.bar
foo.bar:  Invalid parameter/option
$ echo $?
1

Comment 5 Waldo Bastian 2006-06-10 00:39:11 UTC
try
$ ./xdg-mime query filetype foo.bar
Comment 6 Bryce Harrington 2006-06-10 10:42:40 UTC
Okay, the original cases described seem okay:

1.  
 $ ./xdg-mime query filetype foo.bar
 Error:  You must specify an existing file.

2.  
 $ touch foo.bar
 $ ./xdg-mime query filetype foo.bar
 application/x-zerosize

3.
 # chmod 000 foo.bar
 $ ./xdg-mime query filetype foo.bar
 application/x-zerosize

However, according to the man page, xdg-mime also supports a 'default'
parameter, and this seems to be misbehaving:

 $ rm foo.bar
 $ ./xdg-mime query default foo.bar
 Error:  You must specify an existing file.

 $ touch foo.bar
 $ ./xdg-mime query default foo.bar
 basename: missing operand
 Try `basename --help' for more information.

 $ file foo.bar
 foo.bar: empty

But it seems okay with valid file content:

 $ echo 'hello world' > foo.bar 
 $ file foo.bar 
 $ ./xdg-mime query default foo.bar
 kwrite.desktop
 $ file foo.bar 
 foo.bar: ASCII text


Comment 7 Tom Whipple 2006-06-13 09:26:33 UTC
(In reply to comment #3)

> With regard to 2 and 3: There is no guarantee that results in different 
> environments will be the same, is there a reason why the cases described 
> should be treated as special case?

It seems to me that the whole point is to have consistant well defined behavior
across distributions, otherwise applications may count on one behavior but find
another. However, perhaps I have highlighted some exceptional cases here that
should be documented as such.

My goal was not to treat thease cases as special, but just call attention to
what I thougt was a normal case that was not working properly.
Comment 8 Waldo Bastian 2006-06-16 16:33:48 UTC
The case below has been fixed in CVS for Beta1 (at least with KDE) 
 
 $ touch foo.bar 
 $ ./xdg-mime query default foo.bar 
 basename: missing operand 
 Try `basename --help' for more information. 
Comment 9 Waldo Bastian 2006-07-27 12:42:44 UTC
Proposed resolution:
1. (fixed already)
2. WONTFIX
3. Provide custom error message if file is not readable.
Comment 10 Kevin Krammer 2006-07-28 13:38:42 UTC
Created attachment 6382 [details] [review]
File check functions

Possible extension to xdg-utils-common.in for checking the
availability/permissions on input and output files
Comment 11 Kevin Krammer 2006-07-28 14:00:55 UTC
Created attachment 6383 [details] [review]
Improved patch

There is already an exit_failure function for missing files, using that instead
Comment 12 Kevin Krammer 2006-07-28 14:01:27 UTC
Created attachment 6384 [details] [review]
Using check_input_file in xdg-mime
Comment 13 Waldo Bastian 2006-07-28 15:43:35 UTC
Looks good, please commit.
Comment 14 Kevin Krammer 2006-07-29 02:52:36 UTC
Committed the two input files, but left the resulting file untouched since my 
xmlto breaks the description text. Probably some locale setting problem
Comment 15 Waldo Bastian 2006-07-31 08:40:10 UTC
Thanks, will regenerate file.
Comment 16 Waldo Bastian 2006-08-03 13:29:29 UTC
Final resolution
1. FIXED
2. WONTFIX
3. FIXED


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.