[Xfce4-commits] [apps/ristretto] 01/01: Fall back to GFileInfo method in case of libmagic failure
noreply at xfce.org
noreply at xfce.org
Tue Oct 11 15:54:30 CEST 2016
This is an automated email from the git hooks/post-receive script.
f2404 pushed a commit to branch master
in repository apps/ristretto.
commit f5440e7eb6afe814b0868842c575f0152a6ecec3
Author: Igor <f2404 at yandex.ru>
Date: Tue Oct 11 16:53:33 2016 +0300
Fall back to GFileInfo method in case of libmagic failure
Also do not query file content type multiple times
---
src/file.c | 77 +++++++++++++++++++++++++++-----------------------------------
1 file changed, 34 insertions(+), 43 deletions(-)
diff --git a/src/file.c b/src/file.c
index 7caf0c5..d915340 100644
--- a/src/file.c
+++ b/src/file.c
@@ -23,13 +23,13 @@
#include <libxfce4util/libxfce4util.h>
-#include "file.h"
-#include "thumbnailer.h"
-
#if HAVE_MAGIC_H
#include <magic.h>
#endif
+#include "file.h"
+#include "thumbnailer.h"
+
static guint rstto_thumbnail_size[] =
{
THUMBNAIL_SIZE_VERY_SMALL_SIZE,
@@ -398,54 +398,45 @@ rstto_file_get_collate_key ( RsttoFile *r_file )
const gchar *
rstto_file_get_content_type ( RsttoFile *r_file )
{
- const gchar *content_type;
-
-#if HAVE_MAGIC_H
- magic_t magic = NULL;
-
- if ((magic = magic_open(MAGIC_MIME_TYPE)) == NULL)
- {
- fprintf(stderr, "unable to initialize magic library\n");
- return NULL;
- }
-
- if (magic_load(magic, NULL) != 0)
- {
- fprintf(stderr, "cannot load magic database: %s\n", magic_error(magic));
- magic_close(magic);
- return NULL;
- }
-
- content_type = magic_file(magic, rstto_file_get_path(r_file));
-
- if (NULL != content_type)
- {
- r_file->priv->content_type = g_strdup (content_type);
- }
-
- magic_close(magic);
-#else
- GFileInfo *file_info = NULL;
+ const gchar *content_type = NULL;
if ( NULL == r_file->priv->content_type )
{
- file_info = g_file_query_info (
- r_file->priv->file,
- "standard::content-type",
- 0,
- NULL,
- NULL );
- if ( NULL != file_info )
+#if HAVE_MAGIC_H
+ magic_t magic = magic_open(MAGIC_MIME_TYPE);
+ if ( magic != NULL )
+ {
+ if ( magic_load(magic, NULL) == 0 )
+ {
+ content_type = magic_file(magic, rstto_file_get_path(r_file));
+ if ( NULL != content_type )
+ {
+ r_file->priv->content_type = g_strdup (content_type);
+ }
+ }
+ magic_close(magic);
+ }
+#endif
+
+ if ( NULL == content_type )
{
- content_type = g_file_info_get_content_type (file_info);
- if ( NULL != content_type )
+ GFileInfo *file_info = g_file_query_info (
+ r_file->priv->file,
+ "standard::content-type",
+ 0,
+ NULL,
+ NULL );
+ if ( NULL != file_info )
{
- r_file->priv->content_type = g_strdup (content_type);
+ content_type = g_file_info_get_content_type (file_info);
+ if ( NULL != content_type )
+ {
+ r_file->priv->content_type = g_strdup (content_type);
+ }
+ g_object_unref (file_info);
}
- g_object_unref (file_info);
}
}
-#endif
return (const gchar *)r_file->priv->content_type;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list