[gnome-software] Port existing code to use the new os-release parser



commit 6f2bcf78dec17d2fb75be40ab5cb3da230de9ad1
Author: Kalev Lember <klember redhat com>
Date:   Tue Jan 19 19:28:10 2016 +0100

    Port existing code to use the new os-release parser

 src/Makefile.am         |    1 +
 src/gs-plugin.c         |   15 ++++++---------
 src/gs-sources-dialog.c |   17 ++---------------
 3 files changed, 9 insertions(+), 24 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0a66e64..5f46c47 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -78,6 +78,7 @@ gnome_software_cmd_SOURCES =                          \
        gs-app.c                                        \
        gs-cmd.c                                        \
        gs-utils.c                                      \
+       gs-os-release.c                                 \
        gs-plugin-loader.c                              \
        gs-plugin-loader-sync.c                         \
        gs-category.c                                   \
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index b987e33..591bf0d 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -43,8 +43,7 @@
 #include <gio/gdesktopappinfo.h>
 
 #include "gs-plugin.h"
-
-#define GS_PLUGIN_OS_RELEASE_FN                "/etc/os-release"
+#include "gs-os-release.h"
 
 /**
  * gs_plugin_status_to_string:
@@ -85,18 +84,16 @@ gboolean
 gs_plugin_check_distro_id (GsPlugin *plugin, const gchar *distro_id)
 {
        g_autoptr(GError) error = NULL;
-       g_autofree gchar *data = NULL;
-       g_autofree gchar *search = NULL;
+       g_autofree gchar *id = NULL;
 
        /* check that we are running on Fedora */
-       if (!g_file_get_contents (GS_PLUGIN_OS_RELEASE_FN, &data, NULL, &error)) {
-               g_warning ("%s could not be read: %s",
-                          GS_PLUGIN_OS_RELEASE_FN,
+       id = gs_os_release_get_id (&error);
+       if (id == NULL) {
+               g_warning ("Could not parse os-release: %s",
                           error->message);
                return FALSE;
        }
-       search = g_strdup_printf ("ID=%s\n", distro_id);
-       if (g_strstr_len (data, -1, search) == NULL)
+       if (g_strcmp0 (id, distro_id) != 0)
                return FALSE;
        return TRUE;
 }
diff --git a/src/gs-sources-dialog.c b/src/gs-sources-dialog.c
index 9e0714c..9711078 100644
--- a/src/gs-sources-dialog.c
+++ b/src/gs-sources-dialog.c
@@ -26,6 +26,7 @@
 #include <gtk/gtk.h>
 
 #include "gs-sources-dialog.h"
+#include "gs-os-release.h"
 #include "gs-sources-dialog-row.h"
 #include "gs-utils.h"
 
@@ -394,22 +395,8 @@ static gchar *
 get_os_name (void)
 {
        gchar *name = NULL;
-       g_autofree gchar *buffer = NULL;
-
-       if (g_file_get_contents ("/etc/os-release", &buffer, NULL, NULL)) {
-               gchar *start, *end;
-
-               start = end = NULL;
-               if ((start = strstr (buffer, "NAME=")) != NULL) {
-                       start += strlen ("NAME=");
-                       end = strchr (start, '\n');
-               }
-
-               if (start != NULL && end != NULL) {
-                       name = g_strndup (start, end - start);
-               }
-       }
 
+       name = gs_os_release_get_name (NULL);
        if (name == NULL) {
                /* TRANSLATORS: this is the fallback text we use if we can't
                   figure out the name of the operating system */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]