Bug 106894 - xdg-mime returns wrong mime type on generic DE when filename contains a colon
Summary: xdg-mime returns wrong mime type on generic DE when filename contains a colon
Status: RESOLVED MOVED
Alias: None
Product: Portland
Classification: Unclassified
Component: xdg-utils (show other bugs)
Version: 1.1.0 rc1
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Portland Bugs
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-12 04:38 UTC by Jitterman
Modified: 2019-02-16 13:40 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Jitterman 2018-06-12 04:38:57 UTC
The info_generic function in xdg-mime looks like this:

info_generic()                                                                   
{                                                                                
    if mimetype --version >/dev/null 2>&1; then                                  
        DEBUG 1 "Running mimetype -b \"$1\""                                     
        mimetype -b "$1"                                                         
    else                                                                         
        DEBUG 1 "Running file --mime-type \"$1\""                                
        /usr/bin/file --mime-type "$1" 2> /dev/null | cut -d ":" -f 2 | sed s/"^ "//                                       
    fi                                                                           
                                                                                 
    if [ $? -eq 0 ]; then                                                        
        exit_success                                                             
    else                                                                         
        exit_failure_operation_failed                                            
    fi                                                                           
}

The problem occurs if /usr/bin/file is executed and the filename contains the colon.
Normally file outputs both the filename and the mimetype, but only the mimtype is desired so cut is employed to split the output from file into two pieces and return only the second, the mimetype.

I have not spent a lot of time trying to determine the best solution to this problem. What worked for me was to replace the whole line with:

        /usr/bin/file -b --mime-type "$1" 2> /dev/null

The -b option tell file to only output the mimetype and not the filename.
Comment 1 GitLab Migration User 2019-02-16 13:40:18 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/xdg/xdg-utils/issues/130.


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.