summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2015-12-17 21:37:30 +0100
committerAlexander Larsson <alexl@redhat.com>2015-12-17 21:37:30 +0100
commit41b3db5e01183f0d187cc9e8c88d7d794479801e (patch)
tree4aad8995178bf11adec3391751b212f545f37138 /lib
parente6509ff11cfeebe2bb1497b429c1699f8e851fea (diff)
downloadxdg-app-41b3db5e01183f0d187cc9e8c88d7d794479801e.tar.gz
lib: Add xdg_app_installation_list_installed_refs_for_update
Diffstat (limited to 'lib')
-rw-r--r--lib/test-lib.c29
-rw-r--r--lib/xdg-app-installation.c84
-rw-r--r--lib/xdg-app-installation.h3
3 files changed, 116 insertions, 0 deletions
diff --git a/lib/test-lib.c b/lib/test-lib.c
index 72757f9..006f1df 100644
--- a/lib/test-lib.c
+++ b/lib/test-lib.c
@@ -62,6 +62,35 @@ main (int argc, char *argv[])
return 0;
}
+ g_print ("\n**** Checking for updates\n");
+ {
+ g_autoptr(GPtrArray) updates =
+ xdg_app_installation_list_installed_refs_for_update (installation,
+ NULL, &error);
+
+ if (updates == NULL)
+ {
+ g_print ("check for updates error: %s\n", error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ for (i = 0; i < updates->len; i++)
+ {
+ XdgAppInstalledRef *ref = g_ptr_array_index(updates,i);
+ g_print ("%d %s %s %s %s %s %s %d\n",
+ xdg_app_ref_get_kind (XDG_APP_REF(ref)),
+ xdg_app_ref_get_name (XDG_APP_REF(ref)),
+ xdg_app_ref_get_arch (XDG_APP_REF(ref)),
+ xdg_app_ref_get_branch (XDG_APP_REF(ref)),
+ xdg_app_ref_get_commit (XDG_APP_REF(ref)),
+ xdg_app_installed_ref_get_origin (ref),
+ xdg_app_installed_ref_get_deploy_dir (ref),
+ xdg_app_installed_ref_get_is_current (ref));
+ }
+ }
+ }
+
g_print ("\n**** Listing all installed refs\n");
{
g_autoptr(GPtrArray) refs = NULL;
diff --git a/lib/xdg-app-installation.c b/lib/xdg-app-installation.c
index bb85cfa..83f17dd 100644
--- a/lib/xdg-app-installation.c
+++ b/lib/xdg-app-installation.c
@@ -20,6 +20,8 @@
#include "config.h"
+#include <string.h>
+
#include "libgsystem.h"
#include "xdg-app-utils.h"
#include "xdg-app-installation.h"
@@ -390,6 +392,88 @@ xdg_app_installation_list_installed_refs_by_kind (XdgAppInstallation *self,
}
/**
+ * xdg_app_installation_list_installed_refs_for_update:
+ * @self: a #XdgAppInstallation
+ * @cancellable: (nullable): a #GCancellable
+ * @error: return location for a #GError
+ *
+ * Lists the installed references that has a remote update
+ *
+ * Returns: (transfer container) (element-type XdgAppInstalledRef): an GPtrArray of
+ * #XdgAppInstalledRef instances
+ */
+GPtrArray *
+xdg_app_installation_list_installed_refs_for_update (XdgAppInstallation *self,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(GPtrArray) updates = NULL;
+ g_autoptr(GPtrArray) installed = NULL;
+ g_autoptr(GPtrArray) remotes = NULL;
+ g_autoptr(GHashTable) ht = NULL;
+ int i, j;
+
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ remotes = xdg_app_installation_list_remotes (self, cancellable, error);
+ if (remotes == NULL)
+ return NULL;
+
+ for (i = 0; i < remotes->len; i++)
+ {
+ XdgAppRemote *remote = g_ptr_array_index (remotes, i);
+ g_autoptr(GPtrArray) refs = NULL;
+ g_autoptr(GError) local_error = NULL;
+
+ /* We ignore errors here. we don't want one remote to fail us */
+ refs = xdg_app_installation_list_remote_refs_sync (self,
+ xdg_app_remote_get_name (remote),
+ cancellable, &local_error);
+ if (refs != NULL)
+ {
+ for (j = 0; j < refs->len; j++)
+ {
+ XdgAppRemoteRef *remote_ref = g_ptr_array_index (refs, j);
+ g_autofree char *full_ref = xdg_app_ref_format_ref (XDG_APP_REF (remote_ref));
+ g_autofree char *key = g_strdup_printf ("%s:%s", xdg_app_remote_get_name (remote),
+ full_ref);
+
+ g_hash_table_insert (ht, g_steal_pointer (&key),
+ g_strdup (xdg_app_ref_get_commit (XDG_APP_REF (remote_ref))));
+ }
+ }
+ else
+ {
+ g_debug ("Update: Failed to read remote %s: %s\n",
+ xdg_app_remote_get_name (remote),
+ local_error->message);
+ }
+ }
+
+ installed = xdg_app_installation_list_installed_refs (self, cancellable, error);
+ if (installed == NULL)
+ return NULL;
+
+ updates = g_ptr_array_new_with_free_func (g_object_unref);
+
+ for (i = 0; i < installed->len; i++)
+ {
+ XdgAppInstalledRef *installed_ref = g_ptr_array_index (installed, i);
+ g_autofree char *full_ref = xdg_app_ref_format_ref (XDG_APP_REF (installed_ref));
+ g_autofree char *key = g_strdup_printf ("%s:%s", xdg_app_installed_ref_get_origin (installed_ref),
+ full_ref);
+ const char *remote_ref = g_hash_table_lookup (ht, key);
+
+ if (remote_ref != NULL &&
+ strcmp (remote_ref,
+ xdg_app_ref_get_commit (XDG_APP_REF (installed_ref))) != 0)
+ g_ptr_array_add (updates, g_object_ref (installed_ref));
+ }
+
+ return g_steal_pointer (&updates);
+}
+
+
+/**
* xdg_app_installation_list_remotes:
* @self: a #XdgAppInstallation
* @cancellable: (nullable): a #GCancellable
diff --git a/lib/xdg-app-installation.h b/lib/xdg-app-installation.h
index e3e5247..ae6bfa6 100644
--- a/lib/xdg-app-installation.h
+++ b/lib/xdg-app-installation.h
@@ -75,6 +75,9 @@ XDG_APP_EXTERN GPtrArray *xdg_app_installation_list_installed_refs_by_
XdgAppRefKind kind,
GCancellable *cancellable,
GError **error);
+XDG_APP_EXTERN GPtrArray *xdg_app_installation_list_installed_refs_for_update (XdgAppInstallation *self,
+ GCancellable *cancellable,
+ GError **error);
XDG_APP_EXTERN XdgAppInstalledRef * xdg_app_installation_get_installed_ref (XdgAppInstallation *self,
XdgAppRefKind kind,
const char *name,