lib: xdg_app_remote_fetch_ref_sync

For now this downloads the summary file each time.
tingping/wmclass
Alexander Larsson 2015-12-07 16:17:06 +01:00
parent 6558c812af
commit 188bb00b1b
3 changed files with 84 additions and 0 deletions

View File

@ -9,6 +9,7 @@ main (int argc, char *argv[])
XdgAppInstalledRef *app1;
XdgAppInstalledRef *app2;
XdgAppInstalledRef **runtimes;
XdgAppRemoteRef *remote_ref;
XdgAppRemote **remotes;
int i, j;
@ -116,6 +117,27 @@ main (int argc, char *argv[])
xdg_app_remote_ref_get_remote_name (refs[j]));
}
}
g_print ("\n**** Getting remote gedit master on %s\n", xdg_app_remote_get_name (remotes[i]));
remote_ref = xdg_app_remote_fetch_ref_sync (remotes[i],
XDG_APP_REF_KIND_APP,
"org.gnome.gedit", NULL, "master",
NULL, &error);
if (remote_ref)
{
g_print ("%d %s %s %s %s %s\n",
xdg_app_ref_get_kind (XDG_APP_REF(remote_ref)),
xdg_app_ref_get_name (XDG_APP_REF(remote_ref)),
xdg_app_ref_get_arch (XDG_APP_REF(remote_ref)),
xdg_app_ref_get_version (XDG_APP_REF(remote_ref)),
xdg_app_ref_get_commit (XDG_APP_REF(remote_ref)),
xdg_app_remote_ref_get_remote_name (remote_ref));
}
else
{
g_print ("error: %s\n", error->message);
g_clear_error (&error);
}
}
}

View File

@ -215,6 +215,61 @@ xdg_app_remote_list_refs_sync (XdgAppRemote *self,
return (XdgAppRemoteRef **)g_ptr_array_free (g_steal_pointer (&refs), FALSE);
}
/**
* xdg_app_remote_fetch_ref_sync:
* @self: a #XdgAppRemove
* @cancellable: (nullable): a #GCancellable
* @error: return location for a #GError
*
* Gets the current remote version 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 *version,
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;
g_autofree char *ref = NULL;
const char *checksum;
if (version == NULL)
version = "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,
version,
arch);
else
ref = xdg_app_build_runtime_ref (name,
version,
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,

View File

@ -57,5 +57,12 @@ XDG_APP_EXTERN gboolean xdg_app_remote_get_noenumerate (XdgAppRemote *self)
XDG_APP_EXTERN XdgAppRemoteRef **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 *version,
GCancellable *cancellable,
GError **error);
#endif /* __XDG_APP_REMOTE_H__ */