1
0
mirror of https://github.com/bobwen-dev/hunter synced 2025-04-12 00:55:41 +02:00

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

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 }
})
}
}