fix crash in mime_guess when operating on non-regular files

This commit is contained in:
rabite 2019-05-28 15:29:06 +02:00
parent 16866e5aeb
commit caf242986c
1 changed files with 9 additions and 2 deletions

View File

@ -838,8 +838,15 @@ impl File {
let mime = mime_guess::get_mime_type(&ext.to_string_lossy());
Some(mime)
} else {
let mime = tree_magic::from_filepath(&self.path);
mime::Mime::from_str(&mime).ok()
// Fix crash in tree_magic when called on non-regular file
self.meta()
.ok()
.and_then(|meta| {
if meta.is_file() {
let mime = tree_magic::from_filepath(&self.path);
mime::Mime::from_str(&mime).ok()
} else { None }
})
}
}