Nautilus showing incorrect file type for text files with extension .s

I have a mixed language project with some Assembler files, which have file extension “.s”. When any of the source directories containing Assembler files are displayed in Files/Nautilus, the .s files are shown like this:

image

Other files (.c, .cpp, etc.) show as text files. Right clicking on one of the .s files shows the following:

image

However, the file shell command shows them as ASCII text files:

someguy@somesys:~/projects/someproj/src$ file mzzflt*.s
mzzfltc.s: ASCII text
mzzfltr.s: ASCII text

I’m quite sure that this behaviour started recently, although I’m not in a position to prove it. I have the same behaviour on two systems running Ubuntu 22.04 LTS. On one of the two systems, double-clicking one of these files still opens the file in gedit. On the other, it tries unsuccessfully to open it in archive manager.

For both systems:

someguy@somesys::~$ nautilus --version
GNOME nautilus 42.6

Checking if there is anything stupid that I’ve missed.

Nautilus uses shared-mime-info to determine the mime type of file. Maybe that package got updated recently? You can also check what the mime type of a file would be according to that using xdg-mime query filetype mzzfltc.s to make sure the issue is not on the nautilus side.

2 Likes

Thanks Sebastian! shared-mime-info is at 2.1.2 (14 Jan 2022), so almost 2 years old. The output of xdg-mime query filetype mzzfltc.s is consistent with what Nautilus properties for the file shows.

I found this in

  <mime-type type="application/x-ms-dos-executable">
...
    <magic priority="50">
      <match type="string" value="MZ" offset="0"/>
    </magic>

The first two characters of the Assembler files happen to be “MZ”.

A quick test case:

someguy@somesys:~/projects/mimetest$ echo "MZ" > MZFile.s
someguy@somesys:~/projects/mimetest$ echo "mz" > mzFile.s
someguy@somesys:~/projects/mimetest$ xdg-mime query filetype MZFile.s
application/x-ms-dos-executable
someguy@somesys:~/projects/mimetest$ xdg-mime query filetype mzFile.s
text/plain

So it’s a quirk of the file contents. I couldn’t find any <glob pattern="*.s"/>, so it seems that the initial “MZ” is determining the mime type. It’s clearly not Nautilus’s problem.

1 Like

You can create own MIME type that overrides the defaults:

tee /tmp/custom.xml << EOF > /dev/null
<?xml version="1.0" encoding="utf-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-assembly">
<comment>Assembly source code</comment>
<generic-icon name="text-x-generic"/>
<sub-class-of type="text/plain"/>
<glob pattern="*.s"/>
</mime-type>
</mime-info>
EOF
xdg-mime install --novendor /tmp/custom.xml

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.