diff options
author | Alexander Larsson <alexl@redhat.com> | 2015-12-17 20:51:59 +0100 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2015-12-17 20:51:59 +0100 |
commit | 6a507970c52db3125f9e54772b3c838e8d287fc0 (patch) | |
tree | ba9ca4d124d64da7d6134a341ece91bf96e85dc8 /lib | |
parent | 874fce2b775960afaf6e8e56f12ad5ff4cfad58b (diff) | |
download | xdg-app-6a507970c52db3125f9e54772b3c838e8d287fc0.tar.gz |
lib: Move all sync operations from XdgAppRemote to XdgAppInstallation
Its much easier to handle locking etc when all the i/o operations
are on XdgAppInstallation, and the other objects are pure data carriers.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/test-lib.c | 14 | ||||
-rw-r--r-- | lib/xdg-app-installation.c | 122 | ||||
-rw-r--r-- | lib/xdg-app-installation.h | 18 | ||||
-rw-r--r-- | lib/xdg-app-remote.c | 119 | ||||
-rw-r--r-- | lib/xdg-app-remote.h | 16 |
5 files changed, 148 insertions, 141 deletions
diff --git a/lib/test-lib.c b/lib/test-lib.c index 1e782d8..f29deab 100644 --- a/lib/test-lib.c +++ b/lib/test-lib.c @@ -189,7 +189,8 @@ main (int argc, char *argv[]) xdg_app_remote_get_noenumerate (remotes[i])); g_print ("\n**** Listing remote refs on %s\n", xdg_app_remote_get_name (remotes[i])); - refs = xdg_app_remote_list_refs_sync (remotes[i], NULL, NULL); + refs = xdg_app_installation_list_remote_refs_sync (installation, xdg_app_remote_get_name (remotes[i]), + NULL, NULL); if (refs) { for (j = 0; j < refs->len; j++) @@ -207,10 +208,10 @@ main (int argc, char *argv[]) g_print ("\n**** Getting remote gedit master on %s\n", xdg_app_remote_get_name (remotes[i])); error = NULL; - remote_ref = xdg_app_remote_fetch_ref_sync (remotes[i], - XDG_APP_REF_KIND_APP, - "org.gnome.gedit", NULL, "master", - NULL, &error); + remote_ref = xdg_app_installation_fetch_remote_ref_sync (installation, xdg_app_remote_get_name (remotes[i]), + XDG_APP_REF_KIND_APP, + "org.gnome.gedit", NULL, "master", + NULL, &error); if (remote_ref) { GBytes *metadata; @@ -223,7 +224,8 @@ main (int argc, char *argv[]) xdg_app_ref_get_commit (XDG_APP_REF(remote_ref)), xdg_app_remote_ref_get_remote_name (remote_ref)); - metadata = xdg_app_remote_fetch_metadata_sync (remotes[i], xdg_app_ref_get_commit (XDG_APP_REF(remote_ref)), NULL, &error); + metadata = xdg_app_installation_fetch_remote_metadata_sync (installation, xdg_app_remote_get_name (remotes[i]), + xdg_app_ref_get_commit (XDG_APP_REF(remote_ref)), NULL, &error); if (metadata) { g_print ("metadata: %s\n", (char *)g_bytes_get_data (metadata, NULL)); diff --git a/lib/xdg-app-installation.c b/lib/xdg-app-installation.c index 8e8ddb1..3134389 100644 --- a/lib/xdg-app-installation.c +++ b/lib/xdg-app-installation.c @@ -25,6 +25,7 @@ #include "xdg-app-installation.h" #include "xdg-app-installed-ref-private.h" #include "xdg-app-remote-private.h" +#include "xdg-app-remote-ref-private.h" #include "xdg-app-enum-types.h" #include "xdg-app-dir.h" #include "xdg-app-run.h" @@ -856,3 +857,124 @@ xdg_app_installation_uninstall (XdgAppInstallation *self, return TRUE; } + + +GBytes * +xdg_app_installation_fetch_remote_metadata_sync (XdgAppInstallation *self, + const char *remote_name, + const char *commit, + GCancellable *cancellable, + GError **error) +{ + XdgAppInstallationPrivate *priv = xdg_app_installation_get_instance_private (self); + g_autoptr(GBytes) bytes = NULL; + + bytes = xdg_app_dir_fetch_metadata (priv->dir, + remote_name, + commit, + cancellable, + error); + if (bytes == NULL) + return NULL; + + return g_steal_pointer (&bytes); +} + + +/** + * xdg_app_installation_list_remote_refs_sync: + * @self: a #XdgAppInstallation + * @cancellable: (nullable): a #GCancellable + * @error: return location for a #GError + * + * Lists all the refs in a remote. + * + * Returns: (transfer container) (element-type XdgAppInstalledRef): an GPtrArray of + * #XdgAppRemoteRef instances + */ +GPtrArray * +xdg_app_installation_list_remote_refs_sync (XdgAppInstallation *self, + const char *remote_name, + GCancellable *cancellable, + GError **error) +{ + XdgAppInstallationPrivate *priv = xdg_app_installation_get_instance_private (self); + g_autoptr(GPtrArray) refs = g_ptr_array_new_with_free_func (g_object_unref); + g_autoptr(GHashTable) ht = NULL; + GHashTableIter iter; + gpointer key; + gpointer value; + + if (!xdg_app_dir_list_remote_refs (priv->dir, + remote_name, + &ht, + cancellable, + error)) + return NULL; + + g_hash_table_iter_init (&iter, ht); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + const char *refspec = key; + const char *checksum = value; + + g_ptr_array_add (refs, + xdg_app_remote_ref_new (refspec, checksum, remote_name)); + } + + return g_steal_pointer (&refs); +} + +/** + * xdg_app_installation_fetch_remote_ref_sync: + * @self: a #XdgAppRemove + * @cancellable: (nullable): a #GCancellable + * @error: return location for a #GError + * + * Gets the current remote branch of a ref in the remote. + * + * Returns: (transfer full): a #XdgAppRemoteRef instance, or %NULL + */ +XdgAppRemoteRef * +xdg_app_installation_fetch_remote_ref_sync (XdgAppInstallation *self, + const char *remote_name, + XdgAppRefKind kind, + const char *name, + const char *arch, + const char *branch, + GCancellable *cancellable, + GError **error) +{ + XdgAppInstallationPrivate *priv = xdg_app_installation_get_instance_private (self); + g_autoptr(GHashTable) ht = NULL; + g_autofree char *ref = NULL; + const char *checksum; + + if (branch == NULL) + branch = "master"; + + if (!xdg_app_dir_list_remote_refs (priv->dir, + remote_name, + &ht, + cancellable, + error)) + return NULL; + + if (kind == XDG_APP_REF_KIND_APP) + ref = xdg_app_build_app_ref (name, + branch, + arch); + else + ref = xdg_app_build_runtime_ref (name, + branch, + arch); + + checksum = g_hash_table_lookup (ht, ref); + + if (checksum != NULL) + return xdg_app_remote_ref_new (ref, checksum, remote_name); + + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, + "Reference %s doesn't exist in remote\n", ref); + return NULL; +} diff --git a/lib/xdg-app-installation.h b/lib/xdg-app-installation.h index b58e693..339fa5f 100644 --- a/lib/xdg-app-installation.h +++ b/lib/xdg-app-installation.h @@ -122,4 +122,22 @@ XDG_APP_EXTERN gboolean xdg_app_installation_uninstall GCancellable *cancellable, GError **error); +XDG_APP_EXTERN GBytes * xdg_app_installation_fetch_remote_metadata_sync (XdgAppInstallation *self, + const char *remote_name, + const char *commit, + GCancellable *cancellable, + GError **error); +XDG_APP_EXTERN GPtrArray * xdg_app_installation_list_remote_refs_sync (XdgAppInstallation *self, + const char *remote_name, + GCancellable *cancellable, + GError **error); +XDG_APP_EXTERN XdgAppRemoteRef *xdg_app_installation_fetch_remote_ref_sync (XdgAppInstallation *self, + const char *remote_name, + XdgAppRefKind kind, + const char *name, + const char *arch, + const char *branch, + GCancellable *cancellable, + GError **error); + #endif /* __XDG_APP_INSTALLATION_H__ */ diff --git a/lib/xdg-app-remote.c b/lib/xdg-app-remote.c index d51a15b..1ab4727 100644 --- a/lib/xdg-app-remote.c +++ b/lib/xdg-app-remote.c @@ -171,125 +171,6 @@ xdg_app_remote_get_gpg_verify (XdgAppRemote *self) return FALSE; } -GBytes * -xdg_app_remote_fetch_metadata_sync (XdgAppRemote *self, - const char *commit, - GCancellable *cancellable, - GError **error) -{ - XdgAppRemotePrivate *priv = xdg_app_remote_get_instance_private (self); - g_autoptr(GBytes) bytes = NULL; - - bytes = xdg_app_dir_fetch_metadata (priv->dir, - priv->name, - commit, - cancellable, - error); - if (bytes == NULL) - return NULL; - - return g_steal_pointer (&bytes); -} - - -/** - * xdg_app_remote_list_refs_sync: - * @self: a #XdgAppRemove - * @cancellable: (nullable): a #GCancellable - * @error: return location for a #GError - * - * Lists all the refs in a #XdgAppRemote. - * - * Returns: (transfer container) (element-type XdgAppInstalledRef): an GPtrArray of - * #XdgAppRemoteRef instances - */ -GPtrArray * -xdg_app_remote_list_refs_sync (XdgAppRemote *self, - GCancellable *cancellable, - GError **error) -{ - XdgAppRemotePrivate *priv = xdg_app_remote_get_instance_private (self); - g_autoptr(GPtrArray) refs = g_ptr_array_new_with_free_func (g_object_unref); - g_autoptr(GHashTable) ht = NULL; - GHashTableIter iter; - gpointer key; - gpointer value; - - if (!xdg_app_dir_list_remote_refs (priv->dir, - priv->name, - &ht, - cancellable, - error)) - return NULL; - - g_hash_table_iter_init (&iter, ht); - while (g_hash_table_iter_next (&iter, &key, &value)) - { - const char *refspec = key; - const char *checksum = value; - - g_ptr_array_add (refs, - xdg_app_remote_ref_new (refspec, checksum, priv->name)); - } - - return g_steal_pointer (&refs); -} - -/** - * xdg_app_remote_fetch_ref_sync: - * @self: a #XdgAppRemove - * @cancellable: (nullable): a #GCancellable - * @error: return location for a #GError - * - * Gets the current remote branch of a ref in the #XdgAppRemote. - * - * Returns: (transfer full): a #XdgAppRemoteRef instance, or %NULL - */ -XdgAppRemoteRef * -xdg_app_remote_fetch_ref_sync (XdgAppRemote *self, - XdgAppRefKind kind, - const char *name, - const char *arch, - const char *branch, - GCancellable *cancellable, - GError **error) -{ - XdgAppRemotePrivate *priv = xdg_app_remote_get_instance_private (self); - g_autoptr(GHashTable) ht = NULL; - g_autofree char *ref = NULL; - const char *checksum; - - if (branch == NULL) - branch = "master"; - - if (!xdg_app_dir_list_remote_refs (priv->dir, - priv->name, - &ht, - cancellable, - error)) - return NULL; - - if (kind == XDG_APP_REF_KIND_APP) - ref = xdg_app_build_app_ref (name, - branch, - arch); - else - ref = xdg_app_build_runtime_ref (name, - branch, - arch); - - checksum = g_hash_table_lookup (ht, ref); - - if (checksum != NULL) - return xdg_app_remote_ref_new (ref, checksum, priv->name); - - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Reference %s doesn't exist in remote\n", ref); - return NULL; -} - - - XdgAppRemote * xdg_app_remote_new (XdgAppDir *dir, const char *name) diff --git a/lib/xdg-app-remote.h b/lib/xdg-app-remote.h index 840cf7d..f8be547 100644 --- a/lib/xdg-app-remote.h +++ b/lib/xdg-app-remote.h @@ -54,20 +54,4 @@ XDG_APP_EXTERN char * xdg_app_remote_get_title (XdgAppRemote *self); XDG_APP_EXTERN gboolean xdg_app_remote_get_gpg_verify (XdgAppRemote *self); XDG_APP_EXTERN gboolean xdg_app_remote_get_noenumerate (XdgAppRemote *self); -XDG_APP_EXTERN GBytes *xdg_app_remote_fetch_metadata_sync (XdgAppRemote *self, - const char *commit, - GCancellable *cancellable, - GError **error); - -XDG_APP_EXTERN GPtrArray *xdg_app_remote_list_refs_sync (XdgAppRemote *self, - GCancellable *cancellable, - GError **error); -XDG_APP_EXTERN XdgAppRemoteRef *xdg_app_remote_fetch_ref_sync (XdgAppRemote *self, - XdgAppRefKind kind, - const char *name, - const char *arch, - const char *branch, - GCancellable *cancellable, - GError **error); - #endif /* __XDG_APP_REMOTE_H__ */ |