mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 13:46:01 +01:00
Fix the logic in guess_type
This commit is contained in:
parent
1899011a6c
commit
0a92abe720
1 changed files with 9 additions and 4 deletions
13
document.c
13
document.c
|
@ -520,6 +520,7 @@ zathura_document_get_information(zathura_document_t* document, zathura_error_t*
|
||||||
static const gchar*
|
static const gchar*
|
||||||
guess_type(const char* path)
|
guess_type(const char* path)
|
||||||
{
|
{
|
||||||
|
const gchar* content_type = NULL;
|
||||||
#ifdef WITH_MAGIC
|
#ifdef WITH_MAGIC
|
||||||
const char* mime_type = NULL;
|
const char* mime_type = NULL;
|
||||||
|
|
||||||
|
@ -547,20 +548,24 @@ guess_type(const char* path)
|
||||||
mime_type = magic_file(magic, path);
|
mime_type = magic_file(magic, path);
|
||||||
if (mime_type == NULL) {
|
if (mime_type == NULL) {
|
||||||
girara_debug("failed guessing filetype: %s\n", magic_error(magic));
|
girara_debug("failed guessing filetype: %s\n", magic_error(magic));
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
girara_debug("magic detected filetype: %s\n", mime_type);
|
||||||
|
content_type = g_strdup(mime_type);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (magic != NULL) {
|
if (magic != NULL) {
|
||||||
magic_close(magic);
|
magic_close(magic);
|
||||||
}
|
}
|
||||||
if (mime_type != NULL) {
|
|
||||||
girara_debug("magic detected filetype: %s\n", mime_type);
|
if (content_type != NULL) {
|
||||||
return g_strdup(mime_type);
|
return content_type;
|
||||||
}
|
}
|
||||||
/* else fallback to g_content_type_guess method */
|
/* else fallback to g_content_type_guess method */
|
||||||
#endif /*WITH_MAGIC*/
|
#endif /*WITH_MAGIC*/
|
||||||
gboolean uncertain = FALSE;
|
gboolean uncertain = FALSE;
|
||||||
const gchar* content_type = g_content_type_guess(path, NULL, 0, &uncertain);
|
content_type = g_content_type_guess(path, NULL, 0, &uncertain);
|
||||||
if (content_type == NULL) {
|
if (content_type == NULL) {
|
||||||
girara_debug("g_content_type failed\n");
|
girara_debug("g_content_type failed\n");
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue