[gnome-software/wip/rancell/apt] Check if a file is a .deb before trying to install it
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/rancell/apt] Check if a file is a .deb before trying to install it
- Date: Mon, 14 Mar 2016 03:39:54 +0000 (UTC)
commit 1191f36540a101a953afc589c1229dfe6179d9a4
Author: Robert Ancell <robert ancell canonical com>
Date: Mon Mar 14 16:39:33 2016 +1300
Check if a file is a .deb before trying to install it
src/plugins/gs-plugin-apt.c | 38 ++++++++++++++++++++++++++++++++++++++
1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/gs-plugin-apt.c b/src/plugins/gs-plugin-apt.c
index f8b2984..7b02631 100644
--- a/src/plugins/gs-plugin-apt.c
+++ b/src/plugins/gs-plugin-apt.c
@@ -869,6 +869,35 @@ gs_plugin_launch (GsPlugin *plugin,
return gs_plugin_app_launch (plugin, app, error);
}
+static gboolean
+content_type_matches (const gchar *filename,
+ gboolean *matches,
+ GCancellable *cancellable,
+ GError **error)
+{
+ const gchar *content_type;
+ g_autoptr(GFile) file = NULL;
+ g_autoptr(GFileInfo) info = NULL;
+ const gchar *supported_types[] = {
+ "application/vnd.debian.binary-package",
+ NULL };
+
+ /* get content type */
+ file = g_file_new_for_path (filename);
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ G_FILE_QUERY_INFO_NONE,
+ cancellable,
+ error);
+ if (info == NULL)
+ return FALSE;
+
+ content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
+ *matches = g_strv_contains (supported_types, content_type);
+
+ return TRUE;
+}
+
gboolean
gs_plugin_filename_to_app (GsPlugin *plugin,
GList **list,
@@ -876,6 +905,7 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
+ gboolean supported;
GsApp *app;
g_autoptr(GFile) file = NULL;
gchar *argv[5] = { NULL };
@@ -888,6 +918,14 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
g_autofree gchar *path = NULL;
g_auto(GStrv) tokens = NULL;
+ if (!content_type_matches (filename,
+ &supported,
+ cancellable,
+ error))
+ return FALSE;
+ if (!supported)
+ return TRUE;
+
argv[0] = argv0 = g_strdup ("dpkg-deb");
argv[1] = argv1 = g_strdup ("--showformat=${Package}\\n"
"${Version}\\n"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]