Bug 460898

Summary: Single-File-Plugin takes priority over LibArchive when handling a MIME subtype of a compressed tar archive.
Product: [Applications] ark Reporter: Jan Felix Langenbach <JanFelix.Langenbach>
Component: generalAssignee: Elvis Angelaccio <elvis.angelaccio>
Status: REPORTED ---    
Severity: normal CC: aacid, rthomsen6
Priority: NOR    
Version First Reported In: 22.08.1   
Target Milestone: ---   
Platform: Manjaro   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Jan Felix Langenbach 2022-10-23 14:00:17 UTC
SUMMARY

My general situation is the same as described in https://invent.kde.org/utilities/ark/-/merge_requests/22#note_176062 although the issue is different.

I am trying to open an ALPM package (file extension `*.pkg.tar.zst`) using a custom MIME type `application/x-zstd-compressed-alpm-package` that inherits from `application/x-zstd-compressed-tar` (see below). But Ark is treating the file like a `application/zstd` single-file-archive, instead of a `application/x-zstd-compressed-tar` compressed `tar` archive.

This is the relevant excerpt from my `~/.local/share/mime/packages/Override.xml`:

  <mime-type type="application/x-zstd-compressed-alpm-package">
    <comment>ALPM package (Zstandard-compressed)</comment>
    <generic-icon name="package-x-generic" />
    <sub-class-of type="application/x-zstd-compressed-tar" />
    <glob pattern="*.pkg.tar.zst" weight="55" />
    <glob pattern="*.pkg.tzst" weight="55" />
  </mime-type>

STEPS TO REPRODUCE
1. Define a MIME type `application/x-zstd-compressed-alpm-package` like above.
2. Update the MIME database.
3. Create a `.tar.zst` file named `mypackage.pkg.tar.zst`.
4. Open that file with Ark.

You can confirm that Ark deduced the correct MIME type under `Archive > Properties`.

OBSERVED RESULT
Ark displays only one entry named `mypackage.pkg.tar`. When double-clicking this entry, Ark opens a new window displaying the contents of the archive.

EXPECTED RESULT
Ark extracts the archive in one step and displays the contents immediately, like it does for any `application/x-zstd-compressed-tar` file.

SOFTWARE/OS VERSIONS
Operating System: Manjaro Linux
KDE Plasma Version: 5.25.5
KDE Frameworks Version: 5.98.0
Qt Version: 5.15.6

ADDITIONAL INFORMATION
The issue seems to be that the Zstd-module is taking priority over the LibArchive module, when opening a file that belongs to a subtype of `application/x-zstd-compressed-tar`. That means the file is opened like a `application/zstd` file instead of a `application/x-zstd-compressed-tar` file.

The semantically correct thing would be to have the handlers follow the class hierarchy (`application/x-zstd-compressed-alpm-package` extends `application/x-zstd-compressed-tar` extends `application/zstd`), so the handler for `application/x-zstd-compressed-tar` takes priority over the handler for `application/zstd`.

I have tested this both by disabling the Zstd-module, and by lowering the value of `X-KDE-Priority` in `plugins/libsinglefileplugin/kerfuffle_libzstd.json.cmake` prior to compilation. The issue does indeed go away when doing this, although both methods have obvious drawbacks.