forked from Mirrors/flatpak-builder
Merge pull request #30 from matthiasclasen/list-updates
Add an --updates option to the repo-contents command, andtingping/wmclass
commit
71811240b0
|
@ -46,8 +46,8 @@ xdg_app_SOURCES = \
|
|||
xdg-app-utils.h \
|
||||
xdg-app-utils.c \
|
||||
$(NULL)
|
||||
xdg_app_LDADD = $(OSTREE_LIBS)
|
||||
xdg_app_CFLAGS = $(OSTREE_CFLAGS)
|
||||
xdg_app_LDADD = $(OSTREE_LIBS) $(SOUP_LIBS)
|
||||
xdg_app_CFLAGS = $(OSTREE_CFLAGS) $(SOUP_CFLAGS)
|
||||
|
||||
install-exec-hook:
|
||||
$(SUDO_BIN) chown root $(DESTDIR)$(bindir)/xdg-app-helper
|
||||
|
|
|
@ -25,6 +25,9 @@ if test "x$GCC" = "xyes"; then
|
|||
esac
|
||||
fi
|
||||
|
||||
PKG_CHECK_MODULES(SOUP, [libsoup-2.4])
|
||||
AC_SUBST(SOUP_CFLAGS)
|
||||
AC_SUBST(SOUP_LIBS)
|
||||
PKG_CHECK_MODULES(OSTREE, [glib-2.0 libgsystem >= 2015.1 gio-2.0 ostree-1 >= 2015.1])
|
||||
AC_SUBST(OSTREE_CFLAGS)
|
||||
AC_SUBST(OSTREE_LIBS)
|
||||
|
|
|
@ -103,6 +103,14 @@
|
|||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--updates</option></term>
|
||||
|
||||
<listitem><para>
|
||||
Show only those which have updates available.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>-v</option></term>
|
||||
<term><option>--verbose</option></term>
|
||||
|
|
|
@ -219,6 +219,9 @@ xdg_app_builtin_build_export (int argc, char **argv, GCancellable *cancellable,
|
|||
g_print ("Content Written: %u\n", stats.content_objects_written);
|
||||
g_print ("Content Bytes Written: %" G_GUINT64_FORMAT "\n", stats.content_bytes_written);
|
||||
|
||||
if (!ostree_repo_regenerate_summary (repo, NULL, cancellable, error))
|
||||
goto out;
|
||||
|
||||
ret = TRUE;
|
||||
|
||||
out:
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "libgsystem.h"
|
||||
#include <libsoup/soup.h>
|
||||
|
||||
#include "xdg-app-builtins.h"
|
||||
#include "xdg-app-utils.h"
|
||||
|
@ -13,14 +14,60 @@
|
|||
static gboolean opt_show_details;
|
||||
static gboolean opt_only_runtimes;
|
||||
static gboolean opt_only_apps;
|
||||
static gboolean opt_only_updates;
|
||||
|
||||
static GOptionEntry options[] = {
|
||||
{ "show-details", 0, 0, G_OPTION_ARG_NONE, &opt_show_details, "Show arches and branches", NULL },
|
||||
{ "runtimes", 0, 0, G_OPTION_ARG_NONE, &opt_only_runtimes, "Show only runtimes", NULL },
|
||||
{ "apps", 0, 0, G_OPTION_ARG_NONE, &opt_only_apps, "Show only apps", NULL },
|
||||
{ "updates", 0, 0, G_OPTION_ARG_NONE, &opt_only_updates, "Show only those where updates are available", NULL },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static gboolean
|
||||
load_contents (const char *uri, GBytes **contents, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
gs_free char *scheme = NULL;
|
||||
|
||||
scheme = g_uri_parse_scheme (uri);
|
||||
if (strcmp (scheme, "file") == 0)
|
||||
{
|
||||
char *buffer;
|
||||
gsize length;
|
||||
gs_unref_object GFile *file = NULL;
|
||||
|
||||
g_debug ("Loading summary %s using GIO", uri);
|
||||
file = g_file_new_for_uri (uri);
|
||||
if (!g_file_load_contents (file, cancellable, &buffer, &length, NULL, NULL))
|
||||
goto out;
|
||||
|
||||
*contents = g_bytes_new_take (buffer, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
gs_unref_object SoupSession *session = NULL;
|
||||
gs_unref_object SoupMessage *msg = NULL;
|
||||
|
||||
g_debug ("Loading summary %s using libsoup", uri);
|
||||
session = soup_session_new ();
|
||||
msg = soup_message_new ("GET", uri);
|
||||
soup_session_send_message (session, msg);
|
||||
|
||||
if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
|
||||
goto out;
|
||||
|
||||
*contents = g_bytes_new (msg->response_body->data, msg->response_body->length);
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
|
||||
g_debug ("Received %ld bytes", g_bytes_get_size (*contents));
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
xdg_app_builtin_repo_contents (int argc, char **argv, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
|
@ -31,9 +78,13 @@ xdg_app_builtin_repo_contents (int argc, char **argv, GCancellable *cancellable,
|
|||
gs_unref_hashtable GHashTable *refs = NULL;
|
||||
GHashTableIter iter;
|
||||
gpointer key;
|
||||
gpointer value;
|
||||
gs_unref_ptrarray GPtrArray *names = NULL;
|
||||
int i;
|
||||
const char *repository;
|
||||
gs_free char *url = NULL;
|
||||
gs_free char *summary_url = NULL;
|
||||
gs_unref_bytes GBytes *bytes = NULL;
|
||||
|
||||
context = g_option_context_new (" REPOSITORY - Show available runtimes and applications");
|
||||
|
||||
|
@ -49,15 +100,54 @@ xdg_app_builtin_repo_contents (int argc, char **argv, GCancellable *cancellable,
|
|||
repository = argv[1];
|
||||
|
||||
repo = xdg_app_dir_get_repo (dir);
|
||||
if (!ostree_repo_list_refs (repo, NULL, &refs, cancellable, error))
|
||||
if (!ostree_repo_remote_get_url (repo, repository, &url, error))
|
||||
goto out;
|
||||
|
||||
summary_url = g_build_filename (url, "summary", NULL);
|
||||
if (load_contents (summary_url, &bytes, cancellable, NULL))
|
||||
{
|
||||
gs_unref_variant GVariant *summary;
|
||||
gs_unref_variant GVariant *ref_list;
|
||||
int n;
|
||||
|
||||
refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||
|
||||
summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, bytes, FALSE);
|
||||
ref_list = g_variant_get_child_value (summary, 0);
|
||||
n = g_variant_n_children (ref_list);
|
||||
g_debug ("Summary contains %d refs", n);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
gs_unref_variant GVariant *ref = NULL;
|
||||
gs_unref_variant GVariant *csum_v = NULL;
|
||||
char *refname;
|
||||
char *checksum;
|
||||
|
||||
ref = g_variant_get_child_value (ref_list, i);
|
||||
g_variant_get (ref, "(&s(t@aya{sv}))", &refname, NULL, &csum_v, NULL);
|
||||
|
||||
g_debug ("%s summary: %s -> %s\n", repository, refname, checksum);
|
||||
if (!ostree_validate_rev (refname, error))
|
||||
goto out;
|
||||
|
||||
checksum = ostree_checksum_from_bytes_v (csum_v);
|
||||
g_hash_table_insert (refs, g_strdup (refname), checksum);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_printerr ("Failed to load summary file for remote %s, listing local refs\n", repository);
|
||||
if (!ostree_repo_list_refs (repo, NULL, &refs, cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
|
||||
names = g_ptr_array_new_with_free_func (g_free);
|
||||
|
||||
g_hash_table_iter_init (&iter, refs);
|
||||
while (g_hash_table_iter_next (&iter, &key, NULL))
|
||||
while (g_hash_table_iter_next (&iter, &key, &value))
|
||||
{
|
||||
const char *refspec = key;
|
||||
const char *checksum = value;
|
||||
gs_free char *remote = NULL;
|
||||
gs_free char *ref = NULL;
|
||||
char *name = NULL;
|
||||
|
@ -66,9 +156,21 @@ xdg_app_builtin_repo_contents (int argc, char **argv, GCancellable *cancellable,
|
|||
if (!ostree_parse_refspec (refspec, &remote, &ref, error))
|
||||
goto out;
|
||||
|
||||
if (!g_str_equal (remote, repository))
|
||||
if (remote != NULL && !g_str_equal (remote, repository))
|
||||
continue;
|
||||
|
||||
if (opt_only_updates)
|
||||
{
|
||||
gs_free char *deployed = NULL;
|
||||
|
||||
deployed = xdg_app_dir_read_active (dir, ref, cancellable);
|
||||
if (deployed == NULL)
|
||||
continue;
|
||||
|
||||
if (g_strcmp0 (deployed, checksum) == 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (g_str_has_prefix (ref, "runtime/") && !opt_only_apps)
|
||||
{
|
||||
name = g_strdup (ref + strlen ("runtime/"));
|
||||
|
|
Loading…
Reference in New Issue