diff options
author | Jehan <jehan@girinstud.io> | 2019-01-07 14:35:21 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2019-03-26 06:15:15 -0400 |
commit | 7640ddc29fb1f7c852162d57d94e606f97f99711 (patch) | |
tree | 29ccad89087cd55cd4b3fb2e0ec94a29b4120bd0 /libappstream-glib/as-node.c | |
parent | 2eb9b8caf9ca22ac914b63f34fea5dd6da6f4e76 (diff) | |
download | appstream-glib-7640ddc29fb1f7c852162d57d94e606f97f99711.tar.gz |
Allow building on Windows
Signed-off-by: Richard Hughes <richard@hughsie.com>
Diffstat (limited to 'libappstream-glib/as-node.c')
-rw-r--r-- | libappstream-glib/as-node.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/libappstream-glib/as-node.c b/libappstream-glib/as-node.c index d64a169..cb3ad5c 100644 --- a/libappstream-glib/as-node.c +++ b/libappstream-glib/as-node.c @@ -935,6 +935,7 @@ as_node_from_file (GFile *file, gsize chunk_size = 32 * 1024; gssize len; g_autofree gchar *data = NULL; + g_autofree gchar *mime_type = NULL; g_autoptr(GMarkupParseContext) ctx = NULL; g_autoptr(GConverter) conv = NULL; g_autoptr(GFileInfo) info = NULL; @@ -961,18 +962,22 @@ as_node_from_file (GFile *file, if (file_stream == NULL) return NULL; content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); - if (g_strcmp0 (content_type, "application/gzip") == 0 || - g_strcmp0 (content_type, "application/x-gzip") == 0) { - conv = G_CONVERTER (g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP)); - stream_data = g_converter_input_stream_new (file_stream, conv); - } else if (g_strcmp0 (content_type, "application/xml") == 0) { - stream_data = g_object_ref (file_stream); - } else { + mime_type = g_content_type_get_mime_type (content_type); + if (mime_type != NULL) { + if (g_strcmp0 (mime_type, "application/gzip") == 0 || + g_strcmp0 (mime_type, "application/x-gzip") == 0) { + conv = G_CONVERTER (g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP)); + stream_data = g_converter_input_stream_new (file_stream, conv); + } else if (g_strcmp0 (mime_type, "application/xml") == 0 || + g_strcmp0 (mime_type, "text/xml") == 0) { + stream_data = g_object_ref (file_stream); + } + } + if (stream_data == NULL) { g_set_error (error, AS_NODE_ERROR, AS_NODE_ERROR_FAILED, - "cannot process file of type %s", - content_type); + "cannot process file of type %s", content_type); return NULL; } |