remote-ls/info: Add --sideloaded option

This means we load the info from sideloaded repos only
This commit is contained in:
Alexander Larsson
2020-03-24 16:17:06 +01:00
parent 9c6bdc5bfd
commit e5e498c34f
4 changed files with 31 additions and 16 deletions

View File

@@ -47,6 +47,7 @@ static gboolean opt_log;
static gboolean opt_show_runtime;
static gboolean opt_show_sdk;
static gboolean opt_cached;
static gboolean opt_sideloaded;
static GOptionEntry options[] = {
{ "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, N_("Arch to install for"), N_("ARCH") },
@@ -61,6 +62,7 @@ static GOptionEntry options[] = {
{ "show-runtime", 0, 0, G_OPTION_ARG_NONE, &opt_show_runtime, N_("Show runtime"), NULL },
{ "show-sdk", 0, 0, G_OPTION_ARG_NONE, &opt_show_sdk, N_("Show sdk"), NULL },
{ "cached", 0, 0, G_OPTION_ARG_NONE, &opt_cached, N_("Use local caches even if they are stale"), NULL },
{ "sideloaded", 0, 0, G_OPTION_ARG_NONE, &opt_sideloaded, N_("Only list refs available as sideloads"), NULL },
{ NULL }
};
@@ -140,7 +142,7 @@ flatpak_builtin_remote_info (int argc, char **argv, GCancellable *cancellable, G
if (ref == NULL)
return FALSE;
state = get_remote_state (preferred_dir, remote, opt_cached, cancellable, error);
state = get_remote_state (preferred_dir, remote, opt_cached, opt_sideloaded, cancellable, error);
if (state == NULL)
return FALSE;

View File

@@ -41,6 +41,7 @@ static gboolean opt_app;
static gboolean opt_all;
static gboolean opt_only_updates;
static gboolean opt_cached;
static gboolean opt_sideloaded;
static char *opt_arch;
static char *opt_app_runtime;
static const char **opt_cols;
@@ -55,6 +56,7 @@ static GOptionEntry options[] = {
{ "app-runtime", 0, 0, G_OPTION_ARG_STRING, &opt_app_runtime, N_("List all applications using RUNTIME"), N_("RUNTIME") },
{ "columns", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_cols, N_("What information to show"), N_("FIELD,…") },
{ "cached", 0, 0, G_OPTION_ARG_NONE, &opt_cached, N_("Use local caches even if they are stale"), NULL },
{ "sideloaded", 0, 0, G_OPTION_ARG_NONE, &opt_sideloaded, N_("Only list refs available as sideloads"), NULL },
{ NULL }
};
@@ -280,12 +282,12 @@ ls_remote (GHashTable *refs_hash, const char **arches, const char *app_runtime,
if (need_cache_data)
{
const char *metadata = NULL;
g_autofree char *metadata = NULL;
g_autoptr(GKeyFile) metakey = NULL;
if (!flatpak_remote_state_lookup_cache (state, ref,
&download_size, &installed_size, &metadata,
NULL, error))
if (!flatpak_remote_state_load_data (state, ref,
&download_size, &installed_size, &metadata,
error))
return FALSE;
metakey = g_key_file_new ();
@@ -439,7 +441,7 @@ flatpak_builtin_remote_ls (int argc, char **argv, GCancellable *cancellable, GEr
return FALSE;
}
state = get_remote_state (preferred_dir, argv[1], opt_cached, cancellable, error);
state = get_remote_state (preferred_dir, argv[1], opt_cached, opt_sideloaded, cancellable, error);
if (state == NULL)
return FALSE;
@@ -474,7 +476,7 @@ flatpak_builtin_remote_ls (int argc, char **argv, GCancellable *cancellable, GEr
if (flatpak_dir_get_remote_disabled (dir, remote_name))
continue;
state = get_remote_state (dir, remote_name, opt_cached,
state = get_remote_state (dir, remote_name, opt_cached, opt_sideloaded,
cancellable, error);
if (state == NULL)
return FALSE;

View File

@@ -1349,23 +1349,33 @@ FlatpakRemoteState *
get_remote_state (FlatpakDir *dir,
const char *remote,
gboolean cached,
gboolean sideloaded,
GCancellable *cancellable,
GError **error)
{
g_autoptr(GError) local_error = NULL;
FlatpakRemoteState *state;
FlatpakRemoteState *state = NULL;
state = flatpak_dir_get_remote_state (dir, remote, cached, cancellable, &local_error);
if (state == NULL && g_error_matches (local_error, FLATPAK_ERROR, FLATPAK_ERROR_NOT_CACHED))
if (sideloaded)
{
g_clear_error (&local_error);
state = flatpak_dir_get_remote_state (dir, remote, FALSE, cancellable, &local_error);
state = flatpak_dir_get_remote_state_local_only (dir, remote, cancellable, error);
if (state == NULL)
return NULL;
}
if (state == NULL)
else
{
g_propagate_error (error, g_steal_pointer (&local_error));
return NULL;
state = flatpak_dir_get_remote_state (dir, remote, cached, cancellable, &local_error);
if (state == NULL && g_error_matches (local_error, FLATPAK_ERROR, FLATPAK_ERROR_NOT_CACHED))
{
g_clear_error (&local_error);
state = flatpak_dir_get_remote_state (dir, remote, FALSE, cancellable, &local_error);
}
if (state == NULL)
{
g_propagate_error (error, g_steal_pointer (&local_error));
return NULL;
}
}
return state;

View File

@@ -176,6 +176,7 @@ void print_wrapped (int columns,
FlatpakRemoteState * get_remote_state (FlatpakDir *dir,
const char *remote,
gboolean cached,
gboolean sideloaded,
GCancellable *cancellable,
GError **error);