[gnome-software] trivial: Split out a shared plugin helper
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Split out a shared plugin helper
- Date: Thu, 1 Oct 2015 17:05:09 +0000 (UTC)
commit a99a667e1f775af8c1fe294d358dbf7b254c214c
Author: Richard Hughes <richard hughsie com>
Date: Thu Oct 1 16:05:25 2015 +0100
trivial: Split out a shared plugin helper
src/gs-utils.c | 28 ++++++++++++++++++++++++++++
src/gs-utils.h | 2 ++
src/plugins/gs-plugin-fwupd.c | 30 +++---------------------------
3 files changed, 33 insertions(+), 27 deletions(-)
---
diff --git a/src/gs-utils.c b/src/gs-utils.c
index bc3538e..0ea2cbc 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -459,4 +459,32 @@ gs_image_set_from_pixbuf (GtkImage *image, const GdkPixbuf *pixbuf)
gs_image_set_from_pixbuf_with_scale (image, pixbuf, scale);
}
+/**
+ * gs_utils_get_file_age:
+ *
+ * Returns: The time in seconds since the file was modified
+ */
+guint
+gs_utils_get_file_age (const gchar *fn)
+{
+ guint64 now;
+ guint64 mtime;
+ g_autoptr(GFile) file = NULL;
+ g_autoptr(GFileInfo) info = NULL;
+
+ file = g_file_new_for_path (fn);
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+ if (info == NULL)
+ return G_MAXUINT;
+ mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ now = (guint64) g_get_real_time () / G_USEC_PER_SEC;
+ if (mtime > now)
+ return G_MAXUINT;
+ return now - mtime;
+}
+
/* vim: set noexpandtab: */
diff --git a/src/gs-utils.h b/src/gs-utils.h
index fddc874..1bbc09c 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -34,6 +34,8 @@ void gs_stop_spinner (GtkSpinner *spinner);
void gs_container_remove_all (GtkContainer *container);
void gs_grab_focus_when_mapped (GtkWidget *widget);
+guint gs_utils_get_file_age (const gchar *fn);
+
void gs_app_notify_installed (GsApp *app);
void gs_app_notify_failed_modal (GsApp *app,
GtkWindow *parent_window,
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index d4629ac..9f20d68 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -31,6 +31,8 @@
#include <gs-plugin.h>
+#include "gs-utils.h"
+
struct GsPluginPrivate {
gsize done_init;
GDBusProxy *proxy;
@@ -615,32 +617,6 @@ gs_plugin_fwupd_update_lvfs_metadata (const gchar *data_fn, const gchar *sig_fn,
}
/**
- * gs_plugin_fwupd_get_file_cache_age:
- */
-static guint
-gs_plugin_fwupd_get_file_cache_age (const gchar *fn)
-{
- guint64 now;
- guint64 mtime;
- g_autoptr(GFile) file = NULL;
- g_autoptr(GFileInfo) info = NULL;
-
- file = g_file_new_for_path (fn);
- info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_TIME_MODIFIED,
- G_FILE_QUERY_INFO_NONE,
- NULL,
- NULL);
- if (info == NULL)
- return G_MAXUINT;
- mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
- now = (guint64) g_get_real_time () / G_USEC_PER_SEC;
- if (mtime > now)
- return G_MAXUINT;
- return now - mtime;
-}
-
-/**
* gs_plugin_fwupd_check_lvfs_metadata:
*/
static gboolean
@@ -674,7 +650,7 @@ gs_plugin_fwupd_check_lvfs_metadata (GsPlugin *plugin,
/* check cache age */
if (cache_age > 0) {
guint tmp;
- tmp = gs_plugin_fwupd_get_file_cache_age (plugin->priv->lvfs_sig_fn);
+ tmp = gs_utils_get_file_age (plugin->priv->lvfs_sig_fn);
if (tmp < cache_age) {
g_debug ("%s is only %i seconds old, so ignoring refresh",
plugin->priv->lvfs_sig_fn, tmp);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]