Add remote-info command

This shows information about a ref in a remote. Of particular interest
is the --log option which gives you a history which can be used
with update --commit=XXX to roll back an update.

Closes: #1174
Approved by: alexlarsson
This commit is contained in:
Alexander Larsson
2017-11-15 19:29:49 +01:00
committed by Atomic Bot
parent a026da8027
commit 0a9ae464f6
8 changed files with 572 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ flatpak_SOURCES = \
app/flatpak-builtins-delete-remote.c \
app/flatpak-builtins-list-remotes.c \
app/flatpak-builtins-ls-remote.c \
app/flatpak-builtins-info-remote.c \
app/flatpak-builtins-install.c \
app/flatpak-builtins-override.c \
app/flatpak-builtins-make-current.c \

View File

@@ -0,0 +1,327 @@
/*
* Copyright © 2017 Red Hat, Inc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Alexander Larsson <alexl@redhat.com>
*/
#include "config.h"
#include <locale.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <glib/gi18n.h>
#include "libglnx/libglnx.h"
#include "flatpak-builtins.h"
#include "flatpak-utils.h"
#include "flatpak-table-printer.h"
static char *opt_arch;
static char *opt_commit;
static gboolean opt_runtime;
static gboolean opt_app;
static gboolean opt_show_ref;
static gboolean opt_show_commit;
static gboolean opt_show_parent;
static gboolean opt_show_metadata;
static gboolean opt_log;
static GOptionEntry options[] = {
{ "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, N_("Arch to install for"), N_("ARCH") },
{ "commit", 0, 0, G_OPTION_ARG_STRING, &opt_commit, N_("Commit to show info for"), N_("COMMIT") },
{ "runtime", 0, 0, G_OPTION_ARG_NONE, &opt_runtime, N_("Look for runtime with the specified name"), NULL },
{ "app", 0, 0, G_OPTION_ARG_NONE, &opt_app, N_("Look for app with the specified name"), NULL },
{ "log", 0, 0, G_OPTION_ARG_NONE, &opt_log, N_("Display log"), NULL },
{ "show-ref", 'r', 0, G_OPTION_ARG_NONE, &opt_show_ref, N_("Show ref"), NULL },
{ "show-commit", 'c', 0, G_OPTION_ARG_NONE, &opt_show_commit, N_("Show commit"), NULL },
{ "show-parent", 'p', 0, G_OPTION_ARG_NONE, &opt_show_parent, N_("Show parent"), NULL },
{ "show-metadata", 'm', 0, G_OPTION_ARG_NONE, &opt_show_metadata, N_("Show metadata"), NULL },
{ NULL }
};
static void
maybe_print_space (gboolean *first)
{
if (*first)
*first = FALSE;
else
g_print (" ");
}
static gchar *
format_timestamp (guint64 timestamp)
{
GDateTime *dt;
gchar *str;
dt = g_date_time_new_from_unix_utc (timestamp);
if (dt == NULL)
return g_strdup ("?");
str = g_date_time_format (dt, "%Y-%m-%d %H:%M:%S +0000");
g_date_time_unref (dt);
return str;
}
gboolean
flatpak_builtin_info_remote (int argc, char **argv, GCancellable *cancellable, GError **error)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GVariant) commit_v = NULL;
g_autoptr(GVariant) commit_metadata = NULL;
const char *remote;
const char *pref;
g_autofree char *default_branch = NULL;
FlatpakKinds kinds;
FlatpakKinds matched_kinds;
g_autofree char *id = NULL;
g_autofree char *arch = NULL;
g_autofree char *branch = NULL;
g_auto(GStrv) parts = NULL;
FlatpakKinds kind;
g_autofree char *ref = NULL;
g_autofree char *commit = NULL;
g_autofree char *parent = NULL;
const char *on = "";
const char *off = "";
gboolean friendly = TRUE;
const char *xa_metadata = NULL;
g_autoptr(GKeyFile) metakey = NULL;
guint64 installed_size = 0;
guint64 download_size = 0;
g_autofree char *formatted_installed_size = NULL;
g_autofree char *formatted_download_size = NULL;
const gchar *subject;
const gchar *body;
guint64 timestamp;
g_autofree char *formatted_timestamp = NULL;
context = g_option_context_new (_(" REMOTE REF - Show information about installed application and/or runtime in a remote"));
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
if (!flatpak_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
return FALSE;
if (!opt_app && !opt_runtime)
opt_app = opt_runtime = TRUE;
if (argc < 3)
return usage_error (context, _("REMOTE and REF must be specified"), error);
remote = argv[1];
pref = argv[2];
default_branch = flatpak_dir_get_remote_default_branch (dir, remote);
kinds = flatpak_kinds_from_bools (opt_app, opt_runtime);
if (!flatpak_split_partial_ref_arg (pref, kinds, opt_arch, NULL,
&matched_kinds, &id, &arch, &branch, error))
return FALSE;
ref = flatpak_dir_find_remote_ref (dir, remote, id, branch, default_branch, arch,
matched_kinds, &kind, cancellable, error);
if (ref == NULL)
return FALSE;
commit_v = flatpak_dir_fetch_remote_commit (dir, remote, ref, opt_commit, &commit, cancellable, error);
if (commit_v == NULL)
return FALSE;
if (flatpak_fancy_output ())
{
on = FLATPAK_ANSI_BOLD_ON;
off = FLATPAK_ANSI_BOLD_OFF; /* bold off */
}
if (opt_show_ref || opt_show_commit || opt_show_parent || opt_show_metadata)
friendly = FALSE;
if (friendly)
{
g_variant_get (commit_v, "(a{sv}aya(say)&s&stayay)", NULL, NULL, NULL,
&subject, &body, NULL, NULL, NULL);
parent = ostree_commit_get_parent (commit_v);
timestamp = ostree_commit_get_timestamp (commit_v);
commit_metadata = g_variant_get_child_value (commit_v, 0);
g_variant_lookup (commit_metadata, "xa.metadata", "&s", &xa_metadata);
if (xa_metadata == NULL)
return flatpak_fail (error, "Commit has no metadata");
if (g_variant_lookup (commit_metadata, "xa.installed-size", "t", &installed_size))
installed_size = GUINT64_FROM_BE (installed_size);
if (g_variant_lookup (commit_metadata, "xa.download-size", "t", &download_size))
download_size = GUINT64_FROM_BE (download_size);
metakey = g_key_file_new ();
if (!g_key_file_load_from_data (metakey, xa_metadata, -1, 0, error))
return FALSE;
parts = g_strsplit (ref, "/", 0);
formatted_installed_size = g_format_size (installed_size);
formatted_download_size = g_format_size (download_size);
formatted_timestamp = format_timestamp (timestamp);
g_print ("%s%s%s %s\n", on, _("Ref:"), off, ref);
g_print ("%s%s%s %s\n", on, _("ID:"), off, parts[1]);
g_print ("%s%s%s %s\n", on, _("Arch:"), off, parts[2]);
g_print ("%s%s%s %s\n", on, _("Branch:"), off, parts[3]);
g_print ("%s%s%s %s\n", on, _("Date:"), off, formatted_timestamp);
g_print ("%s%s%s %s\n", on, _("Subject:"), off, subject);
g_print ("%s%s%s %s\n", on, _("Commit:"), off, commit);
g_print ("%s%s%s %s\n", on, _("Parent:"), off, parent ? parent : "-");
g_print ("%s%s%s %s\n", on, _("Download size:"), off, formatted_download_size);
g_print ("%s%s%s %s\n", on, _("Installed size:"), off, formatted_installed_size);
if (strcmp (parts[0], "app") == 0)
{
g_autofree char *runtime = NULL;
runtime = g_key_file_get_string (metakey, "Application", "runtime", error);
g_print ("%s%s%s %s\n", on, _("Runtime:"), off, runtime ? runtime : "-");
}
if (opt_log)
{
g_autofree char *p = g_strdup (parent);
g_print ("%s%s%s", on, _("History:"), off);
while (p)
{
g_autofree char *p_parent = NULL;
const gchar *p_subject;
guint64 p_timestamp;
g_autofree char *p_formatted_timestamp = NULL;
g_autoptr(GVariant) p_commit_v = NULL;
p_commit_v = flatpak_dir_fetch_remote_commit (dir, remote, ref, p, NULL, cancellable, NULL);
if (p_commit_v == NULL)
break;
p_parent = ostree_commit_get_parent (p_commit_v);
p_timestamp = ostree_commit_get_timestamp (p_commit_v);
p_formatted_timestamp = format_timestamp (p_timestamp);
g_variant_get (p_commit_v, "(a{sv}aya(say)&s&stayay)", NULL, NULL, NULL,
&p_subject, NULL, NULL, NULL, NULL);
g_print ("\n");
g_print ("%s%s%s %s\n", on, _(" Subject:"), off, p_subject);
g_print ("%s%s%s %s\n", on, _(" Date:"), off, p_formatted_timestamp);
g_print ("%s%s%s %s\n", on, _(" Commit:"), off, p);
g_free (p);
p = g_steal_pointer (&p_parent);
}
}
}
else
{
g_autoptr(GVariant) c_v = g_variant_ref (commit_v);
g_autofree char *c = g_strdup (commit);
do
{
g_autofree char *p = ostree_commit_get_parent (c_v);
gboolean first = TRUE;
if (opt_show_ref)
{
maybe_print_space (&first);
g_print ("%s", ref);
}
if (opt_show_commit)
{
maybe_print_space (&first);
g_print ("%s", c);
}
if (opt_show_parent)
{
maybe_print_space (&first);
g_print ("%s", p ? p : "-");
}
if (!first)
g_print ("\n");
if (opt_show_metadata)
g_print ("%s", xa_metadata);
g_free (c);
c = g_steal_pointer (&p);
g_variant_unref (c_v);
c_v = NULL;
if (c && opt_log)
c_v = flatpak_dir_fetch_remote_commit (dir, remote, ref, c, NULL, cancellable, NULL);
}
while (c_v != NULL);
}
return TRUE;
}
gboolean
flatpak_complete_info_remote (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
FlatpakKinds kinds;
int i;
context = g_option_context_new ("");
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL))
return FALSE;
kinds = flatpak_kinds_from_bools (opt_app, opt_runtime);
switch (completion->argc)
{
case 0:
case 1: /* REMOTE */
flatpak_complete_options (completion, global_entries);
flatpak_complete_options (completion, options);
flatpak_complete_options (completion, user_entries);
{
g_auto(GStrv) remotes = flatpak_dir_list_remotes (dir, NULL, NULL);
if (remotes == NULL)
return FALSE;
for (i = 0; remotes[i] != NULL; i++)
flatpak_complete_word (completion, "%s ", remotes[i]);
}
break;
default: /* REF */
flatpak_complete_partial_ref (completion, kinds, opt_arch, dir, completion->argv[1]);
break;
}
return TRUE;
}

View File

@@ -59,6 +59,7 @@ BUILTINPROTO (add_remote)
BUILTINPROTO (modify_remote)
BUILTINPROTO (delete_remote)
BUILTINPROTO (ls_remote)
BUILTINPROTO (info_remote)
BUILTINPROTO (list_remotes)
BUILTINPROTO (install)
BUILTINPROTO (update)

View File

@@ -92,6 +92,7 @@ static FlatpakCommand commands[] = {
{ "remote-delete", N_("Delete a configured remote"), flatpak_builtin_delete_remote, flatpak_complete_delete_remote },
{ "remote-list", NULL, flatpak_builtin_list_remotes, flatpak_complete_list_remotes, TRUE },
{ "remote-ls", N_("List contents of a configured remote"), flatpak_builtin_ls_remote, flatpak_complete_ls_remote },
{ "remote-info", N_("Show information about a remote app or runtime"), flatpak_builtin_info_remote, flatpak_complete_info_remote },
/* translators: please keep the leading newline and space */
{ N_("\n Build applications") },

View File

@@ -3429,7 +3429,7 @@ flatpak_dir_pull_untrusted_local (FlatpakDir *self,
g_autofree const char **commit_refs = NULL;
if (!g_variant_lookup (new_commit_metadata,
"ostree.ref-binding",
OSTREE_COMMIT_META_KEY_REF_BINDING,
"^a&s",
&commit_refs))
{
@@ -9779,7 +9779,6 @@ flatpak_dir_fetch_remote_object (FlatpakDir *self,
g_autofree char *object_url = NULL;
g_autofree char *part1 = NULL;
g_autofree char *part2 = NULL;
g_autoptr(GBytes) bytes = NULL;
if (!ostree_repo_remote_get_url (self->repo, remote_name, &base_url, error))
@@ -9844,9 +9843,9 @@ flatpak_dir_fetch_remote_commit (FlatpakDir *self,
const char *xa_ref = NULL;
g_autofree const char **commit_refs = NULL;
if ((g_variant_lookup (commit_metadata, "xa.ref", "s", &xa_ref) &&
if ((g_variant_lookup (commit_metadata, "xa.ref", "&s", &xa_ref) &&
g_strcmp0 (xa_ref, ref) != 0) ||
(g_variant_lookup (commit_metadata, "ostree.ref-binding", "^a&s", &commit_refs) &&
(g_variant_lookup (commit_metadata, OSTREE_COMMIT_META_KEY_REF_BINDING, "^a&s", &commit_refs) &&
!g_strv_contains ((const char *const *) commit_refs, ref)))
{
flatpak_fail (error, "commit has no requested ref %s in ref binding metadata", ref);

View File

@@ -24,6 +24,7 @@ man1 = \
flatpak-remote-delete.1 \
flatpak-remote-modify.1 \
flatpak-remote-ls.1 \
flatpak-remote-info.1 \
flatpak-install.1 \
flatpak-config.1 \
flatpak-update.1 \

231
doc/flatpak-remote-info.xml Normal file
View File

@@ -0,0 +1,231 @@
<?xml version='1.0'?> <!--*-nxml-*-->
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<refentry id="flatpak-remote-info">
<refentryinfo>
<title>flatpak remote-info</title>
<productname>flatpak</productname>
<authorgroup>
<author>
<contrib>Developer</contrib>
<firstname>Alexander</firstname>
<surname>Larsson</surname>
<email>alexl@redhat.com</email>
</author>
</authorgroup>
</refentryinfo>
<refmeta>
<refentrytitle>flatpak remote-info</refentrytitle>
<manvolnum>1</manvolnum>
</refmeta>
<refnamediv>
<refname>flatpak-remote-info</refname>
<refpurpose>Show information about an application or runtime in a remote</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>flatpak remote-info</command>
<arg choice="opt" rep="repeat">OPTION</arg>
<arg choice="plain">REMOTE</arg>
<arg choice="plain">REF</arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
Shows information about the runtime or application <arg choice="plain">REF</arg> from the
remote repository with the name <arg choice="plain">REMOTE</arg>.
You can find all configured remote repositories with flatpak remotes.
</para>
<para>
By default, the output is formatted in a friendly format.
If you specify one of the options --show-ref, --show-commit,
--show-parent, or --show-metadata, the output is instead formatted
in a machine-readable format.
</para>
<para>
Unless overridden with the --user or --installation options, this command
uses the default system-wide configuration.
</para>
</refsect1>
<refsect1>
<title>Options</title>
<para>The following options are understood:</para>
<variablelist>
<varlistentry>
<term><option>-h</option></term>
<term><option>--help</option></term>
<listitem><para>
Show help options and exit.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--user</option></term>
<listitem><para>
Use the per-user configuration.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--system</option></term>
<listitem><para>
Use the default system-wide configuration.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--installation=NAME</option></term>
<listitem><para>
Use a system-wide installation specified by <arg choice="plain">NAME</arg>
among those defined in <filename>/etc/flatpak/installations.d/</filename>.
Using <arg choice="plain">--installation=default</arg> is equivalent to using
<arg choice="plain">--system</arg>.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--runtime</option></term>
<listitem><para>
Assume that <arg choice="plain">REF</arg> is a runtimes if not explicitly specified.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--app</option></term>
<listitem><para>
Assume that <arg choice="plain">REF</arg> is an apps if not explicitly specified.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--arch=ARCH</option></term>
<listitem><para>
The default architecture to look for, if not given explicitly in the <arg choice="plain">REF</arg>.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--commit=COMMIT</option></term>
<listitem><para>
Show information about the specific commit, rather than the latest version.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--log</option></term>
<listitem><para>
Display a log of previous versions.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-r</option></term>
<term><option>--show-ref</option></term>
<listitem><para>
Show the matched ref.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-c</option></term>
<term><option>--show-commit</option></term>
<listitem><para>
Show the commit id.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-p</option></term>
<term><option>--show-parent</option></term>
<listitem><para>
Show the parent commit id.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-m</option></term>
<term><option>--show-metadata</option></term>
<listitem><para>
Show the metadata.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-v</option></term>
<term><option>--verbose</option></term>
<listitem><para>
Print debug information during command processing.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--ostree-verbose</option></term>
<listitem><para>
Print OSTree debug information during command processing.
</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Examples</title>
<para>
<command>$ flatpak --user remote-info flathub org.gnome.gedit</command>
</para>
<programlisting>
Ref: app/org.gnome.gedit/x86_64/stable
ID: org.gnome.gedit
Arch: x86_64
Branch: stable
Date: 2017-07-31 16:05:22 +0000
Subject: Build org.gnome.gedit at 3ec291fc1ce4d78220527fa79576f4cc1481ebe5
Commit: 3de7e9dde3bb8382aad9dfbbff20eccd9bf2100bc1887a3619ec0372e8066bf7
Parent: -
Download size: 3,4 MB
Installed size: 11,1 MB
Runtime: org.gnome.Platform/x86_64/3.24
</programlisting>
</refsect1>
<refsect1>
<title>See also</title>
<para>
<citerefentry><refentrytitle>flatpak</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>flatpak-remotes</refentrytitle><manvolnum>1</manvolnum></citerefentry>
<citerefentry><refentrytitle>flatpak-remote-ls</refentrytitle><manvolnum>1</manvolnum></citerefentry>
</para>
</refsect1>
</refentry>

View File

@@ -318,6 +318,13 @@
List contents of a configured remote repository.
</para></listitem>
</varlistentry>
<varlistentry>
<term><citerefentry><refentrytitle>flatpak-remote-info</refentrytitle><manvolnum>1</manvolnum></citerefentry></term>
<listitem><para>
Show information about a ref in a configured remote repository.
</para></listitem>
</varlistentry>
</variablelist>
<para>Commands for building applications:</para>