[gnome-initial-setup/wip/pwithnall/misc-fixes: 17/70] page-util: Add API to read the EOS image version




commit 0b57976473f3b5b6439aac713f68bb34fb4b7669
Author: Mario Sanchez Prada <mario endlessm com>
Date:   Fri Aug 18 13:06:11 2017 +0200

    page-util: Add API to read the EOS image version
    
    This is used in several downstream components, including the factory
    test dialog and the Endless EULA page.
    
    (Rebase 3.38: Fix header used for xattrs.)

 gnome-initial-setup/gis-page-util.c | 67 +++++++++++++++++++++++++++++++++++++
 gnome-initial-setup/gis-page-util.h | 36 ++++++++++++++++++++
 gnome-initial-setup/meson.build     |  2 ++
 3 files changed, 105 insertions(+)
---
diff --git a/gnome-initial-setup/gis-page-util.c b/gnome-initial-setup/gis-page-util.c
new file mode 100644
index 00000000..18db3eb9
--- /dev/null
+++ b/gnome-initial-setup/gis-page-util.c
@@ -0,0 +1,67 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2017 Endless Mobile, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * Written by:
+ *     Mario Sanchez Prada <mario endlessm com>
+ */
+
+#include "config.h"
+
+#include "gis-page-util.h"
+
+#include <errno.h>
+#include <gio/gio.h>
+#include <glib.h>
+#include <sys/types.h>
+#include <sys/xattr.h>
+
+#define EOS_IMAGE_VERSION_XATTR "user.eos-image-version"
+
+gchar *
+gis_page_util_get_image_version (const gchar *path,
+                                 GError     **error)
+{
+  ssize_t attrsize;
+  g_autofree gchar *value = NULL;
+
+  g_return_val_if_fail (path != NULL, NULL);
+
+  attrsize = getxattr (path, EOS_IMAGE_VERSION_XATTR, NULL, 0);
+  if (attrsize >= 0)
+    {
+      value = g_malloc (attrsize + 1);
+      value[attrsize] = 0;
+
+      attrsize = getxattr (path, EOS_IMAGE_VERSION_XATTR, value,
+                           attrsize);
+    }
+
+  if (attrsize >= 0)
+    {
+      return g_steal_pointer (&value);
+    }
+  else
+    {
+      int errsv = errno;
+      g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
+                   "Error examining " EOS_IMAGE_VERSION_XATTR " on %s: %s",
+                   path, g_strerror (errsv));
+      return NULL;
+    }
+}
diff --git a/gnome-initial-setup/gis-page-util.h b/gnome-initial-setup/gis-page-util.h
new file mode 100644
index 00000000..a7d30dfc
--- /dev/null
+++ b/gnome-initial-setup/gis-page-util.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2017 Endless Mobile, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ * Written by:
+ *     Mario Sanchez Prada <mario endlessm com>
+ */
+
+#ifndef __GIS_PAGE_UTIL_H__
+#define __GIS_PAGE_UTIL_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gchar *gis_page_util_get_image_version (const gchar *path,
+                                        GError     **error);
+
+G_END_DECLS
+
+#endif
diff --git a/gnome-initial-setup/meson.build b/gnome-initial-setup/meson.build
index 3a6d3428..61aa9765 100644
--- a/gnome-initial-setup/meson.build
+++ b/gnome-initial-setup/meson.build
@@ -15,6 +15,7 @@ sources += [
     'gis-assistant.c',
     'gis-page.c',
     'gis-page-header.c',
+    'gis-page-util.c',
     'gis-pkexec.c',
     'gis-driver.c',
     'gis-keyring.c',
@@ -22,6 +23,7 @@ sources += [
     'gis-assistant.h',
     'gis-page.h',
     'gis-page-header.h',
+    'gis-page-util.h',
     'gis-pkexec.h',
     'gis-driver.h',
     'gis-keyring.h'


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