Wrong mime-type guessed for some files
Aetf opened this issue · 0 comments
Aetf commented
I noticed that handlr incorrectly guesses some of the Qt Designer UI files' mime type, it should be application/x-designer
, but handlr thinks it is application/x-gtk-builder
.
$ handlr open SettingsWidgetFdoSecrets.ui
no handlers found for 'application/x-gtk-builder'
Directly using xdg-mime
from xdg-utils
returns the correct result:
$ xdg-mime query filetype SettingsWidgetFdoSecrets.ui
application/x-designer
From the code I see that the file name based guess is always preferred over a content-based guess.
However, according to the xdg_mime
doc, the correct behavior is to first do a name-based guess, if the result has multiple matches, do a content-based guess and use the latter as the final result.
I tried a simple PoC and xdg_mime indeed returns the correct result in content guess.
use xdg_mime::SharedMimeInfo;
use std::path::PathBuf;
fn main() {
let path = PathBuf::from("SettingsWidgetFdoSecrets.ui");
let db = SharedMimeInfo::new();
let name_guesses = db.get_mime_types_from_file_name(&path.file_name().unwrap().to_string_lossy());
println!("name guesses: {:?}", name_guesses);
let content_guess = db.guess_mime_type().path(&path).guess();
println!("content guess: {:?}, uncertain {}", content_guess.mime_type(), content_guess.uncertain());
}
prints
name guesses: ["application/x-designer", "application/x-gtk-builder"]
content guess: "application/x-designer", uncertain false
The file used in the above examples:
SettingsWidgetFdoSecrets.ui.zip