app: Move installation management to flatpak-main.c

Some builtin flatpak commands work on a single installation, and others
work on multiple installations (such as the remotes command that lists
both system and user remotes). Currently flatpak_option_context_parse()
only supports returning one installation to its caller, and any commands
that want to support multiple installations have to implement that
themselves which leads to a lot of code duplication.

This commit changes flatpak_option_context_parse() to take three new
flags:

    * FLATPAK_BUILTIN_FLAG_ONE_DIR maintains the old behavior by
returning one installation (i.e. user if --user was passed, system if
--system, etc.).

    * FLATPAK_BUILTIN_FLAG_STANDARD_DIRS will get all the installations
specified by the options, or the user and system ones if none were.

    * FLATPAK_BUILTIN_FLAG_ALL_DIRS includes non-default system
installations along with the user and system ones if none were
specified.

These flags also affect what options are parsed and whether the
directories are ensured to exist, so it makes sense in some
circumstances for callers to pass a NULL out_dirs even when not using
FLATPAK_BUILTIN_FLAG_NO_DIR.

This commit also changes all the callers of
flatpak_option_context_parse() so they maintain their behavior. The only
functional change introduced by this is that using --installation
multiple times for commands that only support one now leads to an
error emitted by flatpak rather than by g_option_context_parse().

A follow-up commit will use this refactoring to make many commands
behave more intelligently in determining which installation to use.

Closes: #1205
Approved by: alexlarsson
This commit is contained in:
Matthew Leeds 2017-12-11 21:08:02 -08:00 committed by Atomic Bot
parent 5815d5e92c
commit 8a59927fde
16 changed files with 301 additions and 375 deletions

View File

@ -305,7 +305,8 @@ flatpak_builtin_add_remote (int argc, char **argv,
GCancellable *cancellable, GError **error)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
g_autoptr(GFile) file = NULL;
g_auto(GStrv) remotes = NULL;
g_autofree char *remote_url = NULL;
@ -321,10 +322,13 @@ flatpak_builtin_add_remote (int argc, char **argv,
g_option_context_add_main_entries (context, common_options, NULL);
if (!flatpak_option_context_parse (context, add_options, &argc, &argv, FLATPAK_BUILTIN_FLAG_OPTIONAL_REPO, &dir,
cancellable, error))
if (!flatpak_option_context_parse (context, add_options, &argc, &argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR | FLATPAK_BUILTIN_FLAG_OPTIONAL_REPO,
&dirs, cancellable, error))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
if (argc < 2)
return usage_error (context, _("NAME must be specified"), error);
@ -424,11 +428,11 @@ gboolean
flatpak_complete_add_remote (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
context = g_option_context_new ("");
g_option_context_add_main_entries (context, common_options, NULL);
if (!flatpak_option_context_parse (context, add_options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL))
if (!flatpak_option_context_parse (context, add_options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR, NULL, NULL, NULL))
return FALSE;
switch (completion->argc)
@ -450,7 +454,8 @@ gboolean
flatpak_builtin_modify_remote (int argc, char **argv, GCancellable *cancellable, GError **error)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
g_autoptr(GKeyFile) config = NULL;
g_autoptr(GBytes) gpg_data = NULL;
const char *remote_name;
@ -461,9 +466,13 @@ flatpak_builtin_modify_remote (int argc, char **argv, GCancellable *cancellable,
g_option_context_add_main_entries (context, common_options, NULL);
if (!flatpak_option_context_parse (context, modify_options, &argc, &argv, 0, &dir, cancellable, error))
if (!flatpak_option_context_parse (context, modify_options, &argc, &argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR,
&dirs, cancellable, error))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
if (argc < 2)
return usage_error (context, _("Remote NAME must be specified"), error);
@ -508,14 +517,18 @@ gboolean
flatpak_complete_modify_remote (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
int i;
context = g_option_context_new ("");
g_option_context_add_main_entries (context, common_options, NULL);
if (!flatpak_option_context_parse (context, modify_options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL))
if (!flatpak_option_context_parse (context, modify_options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR, &dirs, NULL, NULL))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
switch (completion->argc)
{
case 0:

View File

@ -198,14 +198,19 @@ gboolean
flatpak_builtin_config (int argc, char **argv, GCancellable *cancellable, GError **error)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
context = g_option_context_new (_("[KEY [VALUE]] - Manage configuration"));
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
if (!flatpak_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
if (!flatpak_option_context_parse (context, options, &argc, &argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR,
&dirs, cancellable, error))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
if (opt_get)
return get_config (argc, argv, dir, cancellable, error);
else if (opt_set)
@ -224,10 +229,10 @@ gboolean
flatpak_complete_config (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
context = g_option_context_new ("");
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL))
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR, NULL, NULL, NULL))
return FALSE;
switch (completion->argc)

View File

@ -43,7 +43,8 @@ gboolean
flatpak_builtin_delete_remote (int argc, char **argv, GCancellable *cancellable, GError **error)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
const char *remote_name;
context = g_option_context_new (_("NAME - Delete a remote repository"));
@ -51,9 +52,13 @@ flatpak_builtin_delete_remote (int argc, char **argv, GCancellable *cancellable,
g_option_context_add_main_entries (context, delete_options, NULL);
if (!flatpak_option_context_parse (context, NULL, &argc, &argv, 0, &dir, cancellable, error))
if (!flatpak_option_context_parse (context, NULL, &argc, &argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR,
&dirs, cancellable, error))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
if (argc < 2)
return usage_error (context, _("NAME must be specified"), error);
@ -73,13 +78,17 @@ gboolean
flatpak_complete_delete_remote (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
int i;
context = g_option_context_new ("");
if (!flatpak_option_context_parse (context, delete_options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL))
if (!flatpak_option_context_parse (context, delete_options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR, &dirs, NULL, NULL))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
switch (completion->argc)
{
case 0:

View File

@ -86,7 +86,8 @@ 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(GPtrArray) dirs = NULL;
FlatpakDir *dir;
g_autoptr(GVariant) commit_v = NULL;
g_autoptr(GVariant) commit_metadata = NULL;
const char *remote;
@ -119,9 +120,13 @@ flatpak_builtin_info_remote (int argc, char **argv, GCancellable *cancellable, G
context = g_option_context_new (_(" REMOTE REF - Show information about an application 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))
if (!flatpak_option_context_parse (context, options, &argc, &argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR,
&dirs, cancellable, error))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
if (!opt_app && !opt_runtime)
opt_app = opt_runtime = TRUE;
@ -289,15 +294,19 @@ gboolean
flatpak_complete_info_remote (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
FlatpakKinds kinds;
int i;
context = g_option_context_new ("");
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL))
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR, &dirs, NULL, NULL))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
kinds = flatpak_kinds_from_bools (opt_app, opt_runtime);
switch (completion->argc)

View File

@ -328,39 +328,18 @@ gboolean
flatpak_complete_info (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) user_dir = NULL;
g_autoptr(FlatpakDir) system_dir = NULL;
g_autoptr(GPtrArray) system_dirs = NULL;
g_autoptr(GPtrArray) dirs = NULL;
g_autoptr(GError) error = NULL;
gboolean search_all = FALSE;
FlatpakKinds kinds;
int i, j;
context = g_option_context_new ("");
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL))
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_ALL_DIRS, &dirs, NULL, NULL))
return FALSE;
kinds = FLATPAK_KINDS_APP | FLATPAK_KINDS_RUNTIME;
if (!opt_user && !opt_system && opt_installations == NULL)
search_all = TRUE;
if (opt_user || search_all)
user_dir = flatpak_dir_get_user ();
if (search_all)
{
system_dirs = flatpak_dir_get_system_list (NULL, &error);
if (system_dirs == NULL)
{
flatpak_completion_debug ("find system installations error: %s", error->message);
return FALSE;
}
}
if (opt_system)
system_dir = flatpak_dir_get_system_default ();
switch (completion->argc)
{
case 0:
@ -368,47 +347,16 @@ flatpak_complete_info (FlatpakCompletion *completion)
flatpak_complete_options (completion, global_entries);
flatpak_complete_options (completion, options);
if (user_dir)
for (i = 0; i < dirs->len; i++)
{
g_auto(GStrv) refs = flatpak_dir_find_installed_refs (user_dir, NULL, NULL, opt_arch,
FlatpakDir *dir = g_ptr_array_index (dirs, i);
g_auto(GStrv) refs = flatpak_dir_find_installed_refs (dir, NULL, NULL, opt_arch,
kinds, &error);
if (refs == NULL)
flatpak_completion_debug ("find local refs error: %s", error->message);
for (i = 0; refs != NULL && refs[i] != NULL; i++)
for (j = 0; refs != NULL && refs[j] != NULL; j++)
{
g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL);
if (parts)
flatpak_complete_word (completion, "%s ", parts[1]);
}
}
if (system_dirs)
{
for (i = 0; i < system_dirs->len; i++)
{
FlatpakDir *dir = g_ptr_array_index (system_dirs, i);
g_auto(GStrv) refs = flatpak_dir_find_installed_refs (dir, NULL, NULL, opt_arch,
kinds, &error);
if (refs == NULL)
flatpak_completion_debug ("find local refs error: %s", error->message);
for (j = 0; refs != NULL && refs[j] != NULL; j++)
{
g_auto(GStrv) parts = flatpak_decompose_ref (refs[j], NULL);
if (parts)
flatpak_complete_word (completion, "%s ", parts[1]);
}
}
}
if (system_dir)
{
g_auto(GStrv) refs = flatpak_dir_find_installed_refs (system_dir, NULL, NULL, opt_arch,
kinds, &error);
if (refs == NULL)
flatpak_completion_debug ("find local refs error: %s", error->message);
for (i = 0; refs != NULL && refs[i] != NULL; i++)
{
g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL);
g_auto(GStrv) parts = flatpak_decompose_ref (refs[j], NULL);
if (parts)
flatpak_complete_word (completion, "%s ", parts[1]);
}
@ -416,47 +364,16 @@ flatpak_complete_info (FlatpakCompletion *completion)
break;
case 2: /* BRANCH */
if (user_dir)
for (i = 0; i < dirs->len; i++)
{
g_auto(GStrv) refs = flatpak_dir_find_installed_refs (user_dir, completion->argv[1], NULL, opt_arch,
FlatpakDir *dir = g_ptr_array_index (dirs, i);
g_auto(GStrv) refs = flatpak_dir_find_installed_refs (dir, completion->argv[1], NULL, opt_arch,
kinds, &error);
if (refs == NULL)
flatpak_completion_debug ("find remote refs error: %s", error->message);
for (i = 0; refs != NULL && refs[i] != NULL; i++)
for (j = 0; refs != NULL && refs[j] != NULL; j++)
{
g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL);
if (parts)
flatpak_complete_word (completion, "%s ", parts[3]);
}
}
if (system_dirs)
{
for (i = 0; i < system_dirs->len; i++)
{
FlatpakDir *dir = g_ptr_array_index (system_dirs, i);
g_auto(GStrv) refs = flatpak_dir_find_installed_refs (dir, completion->argv[1], NULL, opt_arch,
kinds, &error);
if (refs == NULL)
flatpak_completion_debug ("find remote refs error: %s", error->message);
for (j = 0; refs != NULL && refs[j] != NULL; j++)
{
g_auto(GStrv) parts = flatpak_decompose_ref (refs[j], NULL);
if (parts)
flatpak_complete_word (completion, "%s ", parts[3]);
}
}
}
if (system_dir)
{
g_auto(GStrv) refs = flatpak_dir_find_installed_refs (system_dir, completion->argv[1], NULL, opt_arch,
kinds, &error);
if (refs == NULL)
flatpak_completion_debug ("find remote refs error: %s", error->message);
for (i = 0; refs != NULL && refs[i] != NULL; i++)
{
g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL);
g_auto(GStrv) parts = flatpak_decompose_ref (refs[j], NULL);
if (parts)
flatpak_complete_word (completion, "%s ", parts[3]);
}

View File

@ -458,7 +458,8 @@ gboolean
flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GError **error)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
const char *remote;
char **prefs = NULL;
int i, n_prefs;
@ -470,9 +471,13 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro
context = g_option_context_new (_("LOCATION/REMOTE [REF...] - Install applications or runtimes"));
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
if (!flatpak_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
if (!flatpak_option_context_parse (context, options, &argc, &argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR,
&dirs, cancellable, error))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
if (!opt_bundle && !opt_from && argc >= 2)
{
if (flatpak_file_arg_has_suffix (argv[1], ".flatpakref"))
@ -550,14 +555,18 @@ gboolean
flatpak_complete_install (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
FlatpakKinds kinds;
int i;
context = g_option_context_new ("");
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL))
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR, &dirs, NULL, NULL))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
kinds = flatpak_kinds_from_bools (opt_app, opt_runtime);
switch (completion->argc)

View File

@ -34,15 +34,9 @@
#include "flatpak-table-printer.h"
static gboolean opt_show_details;
static gboolean opt_user;
static gboolean opt_system;
static gboolean opt_show_disabled;
static char **opt_installations;
static GOptionEntry options[] = {
{ "user", 0, 0, G_OPTION_ARG_NONE, &opt_user, N_("Show user installations"), NULL },
{ "system", 0, 0, G_OPTION_ARG_NONE, &opt_system, N_("Show system-wide installations"), NULL },
{ "installation", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_installations, N_("Show specific system-wide installations"), NULL },
{ "show-details", 'd', 0, G_OPTION_ARG_NONE, &opt_show_details, N_("Show remote details"), NULL },
{ "show-disabled", 0, 0, G_OPTION_ARG_NONE, &opt_show_disabled, N_("Show disabled remotes"), NULL },
{ NULL }
@ -59,46 +53,13 @@ flatpak_builtin_list_remotes (int argc, char **argv, GCancellable *cancellable,
context = g_option_context_new (_(" - List remote repositories"));
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error))
if (!flatpak_option_context_parse (context, options, &argc, &argv,
FLATPAK_BUILTIN_FLAG_STANDARD_DIRS, &dirs, cancellable, error))
return FALSE;
if (argc > 1)
return usage_error (context, _("Too many arguments"), error);
if (!opt_user && !opt_system && opt_installations == NULL)
{
/* Default: All system and user remotes */
opt_user = opt_system = TRUE;
}
dirs = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
if (opt_user)
g_ptr_array_add (dirs, flatpak_dir_get_user ());
if (opt_system)
g_ptr_array_add (dirs, flatpak_dir_get_system_default ());
if (opt_installations != NULL)
{
int i = 0;
for (i = 0; opt_installations[i] != NULL; i++)
{
FlatpakDir *installation_dir = NULL;
/* Already included the default system installation. */
if (opt_system && g_strcmp0 (opt_installations[i], "default") == 0)
continue;
installation_dir = flatpak_dir_get_system_by_id (opt_installations[i], cancellable, error);
if (installation_dir == NULL)
return FALSE;
g_ptr_array_add (dirs, installation_dir);
}
}
printer = flatpak_table_printer_new ();
j = 0;
@ -116,8 +77,6 @@ flatpak_builtin_list_remotes (int argc, char **argv, GCancellable *cancellable,
FlatpakDir *dir = g_ptr_array_index (dirs, j);
g_auto(GStrv) remotes = NULL;
flatpak_log_dir_access (dir);
remotes = flatpak_dir_list_remotes (dir, cancellable, error);
if (remotes == NULL)
return FALSE;
@ -158,9 +117,7 @@ flatpak_builtin_list_remotes (int argc, char **argv, GCancellable *cancellable,
flatpak_table_printer_add_column (printer, ""); /* Options */
if ((opt_user && opt_system) || (opt_user && opt_installations != NULL)
|| (opt_system && opt_installations != NULL)
|| (opt_installations != NULL && g_strv_length (opt_installations) > 1))
if (dirs->len > 1)
{
g_autofree char *dir_id = flatpak_dir_get_name (dir);
flatpak_table_printer_append_with_comma (printer, dir_id);
@ -194,10 +151,10 @@ gboolean
flatpak_complete_list_remotes (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
context = g_option_context_new ("");
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL))
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR, NULL, NULL, NULL))
return FALSE;
switch (completion->argc)

View File

@ -34,18 +34,12 @@
#include "flatpak-table-printer.h"
static gboolean opt_show_details;
static gboolean opt_user;
static gboolean opt_system;
static gboolean opt_runtime;
static gboolean opt_app;
static gboolean opt_all;
static char **opt_installations;
static char *opt_arch;
static GOptionEntry options[] = {
{ "user", 0, 0, G_OPTION_ARG_NONE, &opt_user, N_("Show user installations"), NULL },
{ "system", 0, 0, G_OPTION_ARG_NONE, &opt_system, N_("Show system-wide installations"), NULL },
{ "installation", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_installations, N_("Show specific system-wide installations"), NULL },
{ "show-details", 'd', 0, G_OPTION_ARG_NONE, &opt_show_details, N_("Show extra information"), NULL },
{ "runtime", 0, 0, G_OPTION_ARG_NONE, &opt_runtime, N_("List installed runtimes"), NULL },
{ "app", 0, 0, G_OPTION_ARG_NONE, &opt_app, N_("List installed applications"), NULL },
@ -278,87 +272,22 @@ print_table_for_refs (gboolean print_apps, GPtrArray* refs_array, const char *ar
}
static gboolean
print_installed_refs (gboolean app, gboolean runtime, gboolean print_system, gboolean print_user, char **installations, const char *arch, GCancellable *cancellable, GError **error)
print_installed_refs (gboolean app, gboolean runtime, GPtrArray *dirs, const char *arch, GCancellable *cancellable, GError **error)
{
g_autoptr(GPtrArray) refs_array = NULL;
gboolean print_all = !print_user && !print_system && (installations == NULL);
int i;
refs_array = g_ptr_array_new_with_free_func ((GDestroyNotify) refs_data_free);
if (print_user || print_all)
{
g_autoptr(FlatpakDir) user_dir = NULL;
g_auto(GStrv) user_app = NULL;
g_auto(GStrv) user_runtime = NULL;
user_dir =flatpak_dir_get_user ();
flatpak_log_dir_access (user_dir);
if (!find_refs_for_dir (user_dir, app ? &user_app : NULL, runtime ? &user_runtime : NULL, cancellable, error))
for (i = 0; i < dirs->len; i++)
{
FlatpakDir *dir = g_ptr_array_index (dirs, i);
g_auto(GStrv) apps = NULL;
g_auto(GStrv) runtimes = NULL;
if (!find_refs_for_dir (dir, app ? &apps : NULL, runtime ? &runtimes : NULL, cancellable, error))
return FALSE;
g_ptr_array_add (refs_array, refs_data_new (user_dir, user_app, user_runtime));
}
if (print_all)
{
g_autoptr(GPtrArray) system_dirs = NULL;
int i;
system_dirs = flatpak_dir_get_system_list (cancellable, error);
if (system_dirs == NULL)
return FALSE;
for (i = 0; i < system_dirs->len; i++)
{
FlatpakDir *dir = g_ptr_array_index (system_dirs, i);
g_auto(GStrv) apps = NULL;
g_auto(GStrv) runtimes = NULL;
flatpak_log_dir_access (dir);
if (!find_refs_for_dir (dir, app ? &apps : NULL, runtime ? &runtimes : NULL, cancellable, error))
return FALSE;
g_ptr_array_add (refs_array, refs_data_new (dir, apps, runtimes));
}
}
else
{
if (print_system)
{
g_autoptr(FlatpakDir) system_dir = NULL;
g_auto(GStrv) system_app = NULL;
g_auto(GStrv) system_runtime = NULL;
system_dir = flatpak_dir_get_system_default ();
flatpak_log_dir_access (system_dir);
if (!find_refs_for_dir (system_dir, app ? &system_app : NULL, runtime ? &system_runtime : NULL, cancellable, error))
return FALSE;
g_ptr_array_add (refs_array, refs_data_new (system_dir, system_app, system_runtime));
}
if (installations != NULL)
{
g_auto(GStrv) installation_apps = NULL;
g_auto(GStrv) installation_runtimes = NULL;
int i = 0;
for (i = 0; installations[i] != NULL; i++)
{
g_autoptr(FlatpakDir) system_dir = NULL;
/* Already included the default system installation. */
if (print_system && g_strcmp0 (installations[i], "default") == 0)
continue;
system_dir = flatpak_dir_get_system_by_id (installations[i], cancellable, error);
flatpak_log_dir_access (system_dir);
if (system_dir == NULL)
return FALSE;
if (!find_refs_for_dir (system_dir, app ? &installation_apps : NULL, runtime ? &installation_runtimes : NULL, cancellable, error))
return FALSE;
g_ptr_array_add (refs_array, refs_data_new (system_dir, installation_apps, installation_runtimes));
}
}
g_ptr_array_add (refs_array, refs_data_new (dir, apps, runtimes));
}
if (!print_table_for_refs (app, refs_array, arch, cancellable, error))
@ -371,11 +300,14 @@ gboolean
flatpak_builtin_list (int argc, char **argv, GCancellable *cancellable, GError **error)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(GPtrArray) dirs = NULL;
context = g_option_context_new (_(" - List installed apps and/or runtimes"));
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error))
if (!flatpak_option_context_parse (context, options, &argc, &argv,
FLATPAK_BUILTIN_FLAG_ALL_DIRS,
&dirs, cancellable, error))
return FALSE;
if (argc > 1)
@ -388,9 +320,7 @@ flatpak_builtin_list (int argc, char **argv, GCancellable *cancellable, GError *
}
if (!print_installed_refs (opt_app, opt_runtime,
opt_system,
opt_user,
opt_installations,
dirs,
opt_arch,
cancellable, error))
return FALSE;
@ -403,5 +333,6 @@ flatpak_complete_list (FlatpakCompletion *completion)
{
flatpak_complete_options (completion, global_entries);
flatpak_complete_options (completion, options);
flatpak_complete_options (completion, user_entries);
return TRUE;
}

View File

@ -54,7 +54,8 @@ gboolean
flatpak_builtin_ls_remote (int argc, char **argv, GCancellable *cancellable, GError **error)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
GHashTableIter refs_iter;
GHashTableIter iter;
gpointer refs_key;
@ -74,9 +75,13 @@ flatpak_builtin_ls_remote (int argc, char **argv, GCancellable *cancellable, GEr
context = g_option_context_new (_(" [REMOTE] - Show available runtimes and applications"));
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
if (!flatpak_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
if (!flatpak_option_context_parse (context, options, &argc, &argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR,
&dirs, cancellable, error))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
if (!opt_app && !opt_runtime)
opt_app = opt_runtime = TRUE;
@ -279,14 +284,18 @@ gboolean
flatpak_complete_ls_remote (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
int i;
context = g_option_context_new ("");
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL))
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR, &dirs, NULL, NULL))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
switch (completion->argc)
{
case 0:

View File

@ -43,7 +43,8 @@ gboolean
flatpak_builtin_make_current_app (int argc, char **argv, GCancellable *cancellable, GError **error)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
g_autoptr(GFile) deploy_base = NULL;
const char *pref;
const char *default_branch = NULL;
@ -57,9 +58,13 @@ flatpak_builtin_make_current_app (int argc, char **argv, GCancellable *cancellab
context = g_option_context_new (_("APP BRANCH - Make branch of application current"));
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
if (!flatpak_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
if (!flatpak_option_context_parse (context, options, &argc, &argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR,
&dirs, cancellable, error))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
if (argc < 2)
return usage_error (context, _("APP must be specified"), error);
@ -109,15 +114,19 @@ gboolean
flatpak_complete_make_current_app (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
g_autoptr(GError) error = NULL;
g_auto(GStrv) refs = NULL;
int i;
context = g_option_context_new ("");
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL))
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR, &dirs, NULL, NULL))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
switch (completion->argc)
{
case 0:

View File

@ -45,7 +45,8 @@ flatpak_builtin_override (int argc, char **argv, GCancellable *cancellable, GErr
g_autoptr(GOptionContext) context = NULL;
const char *app;
g_autoptr(FlatpakContext) arg_context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
g_autoptr(GKeyFile) metakey = NULL;
g_autoptr(FlatpakContext) overrides = NULL;
g_autoptr(GError) my_error = NULL;
@ -56,9 +57,13 @@ flatpak_builtin_override (int argc, char **argv, GCancellable *cancellable, GErr
arg_context = flatpak_context_new ();
g_option_context_add_group (context, flatpak_context_get_options (arg_context));
if (!flatpak_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
if (!flatpak_option_context_parse (context, options, &argc, &argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR,
&dirs, cancellable, error))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
if (argc < 2)
return usage_error (context, _("APP must be specified"), error);
@ -99,8 +104,7 @@ gboolean
flatpak_complete_override (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) user_dir = NULL;
g_autoptr(FlatpakDir) system_dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
g_autoptr(GError) error = NULL;
int i;
g_autoptr(FlatpakContext) arg_context = NULL;
@ -111,7 +115,7 @@ flatpak_complete_override (FlatpakCompletion *completion)
g_option_context_add_group (context, flatpak_context_get_options (arg_context));
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL))
FLATPAK_BUILTIN_FLAG_STANDARD_DIRS, &dirs, NULL, NULL))
return FALSE;
switch (completion->argc)
@ -122,33 +126,21 @@ flatpak_complete_override (FlatpakCompletion *completion)
flatpak_complete_options (completion, options);
flatpak_context_complete (arg_context, completion);
user_dir = flatpak_dir_get_user ();
{
g_auto(GStrv) refs = flatpak_dir_find_installed_refs (user_dir, NULL, NULL, NULL,
FLATPAK_KINDS_APP, &error);
if (refs == NULL)
flatpak_completion_debug ("find local refs error: %s", error->message);
for (i = 0; refs != NULL && refs[i] != NULL; i++)
{
g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL);
if (parts)
flatpak_complete_word (completion, "%s ", parts[1]);
}
}
system_dir = flatpak_dir_get_system_default ();
{
g_auto(GStrv) refs = flatpak_dir_find_installed_refs (system_dir, NULL, NULL, NULL,
FLATPAK_KINDS_APP, &error);
if (refs == NULL)
flatpak_completion_debug ("find local refs error: %s", error->message);
for (i = 0; refs != NULL && refs[i] != NULL; i++)
{
g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], NULL);
if (parts)
flatpak_complete_word (completion, "%s ", parts[1]);
}
}
for (i = 0; i < dirs->len; i++)
{
FlatpakDir *dir = g_ptr_array_index (dirs, i);
int j;
g_auto(GStrv) refs = flatpak_dir_find_installed_refs (dir, NULL, NULL, NULL,
FLATPAK_KINDS_APP, &error);
if (refs == NULL)
flatpak_completion_debug ("find local refs error: %s", error->message);
for (j = 0; refs != NULL && refs[j] != NULL; j++)
{
g_auto(GStrv) parts = flatpak_decompose_ref (refs[j], NULL);
if (parts)
flatpak_complete_word (completion, "%s ", parts[1]);
}
}
break;

View File

@ -28,17 +28,6 @@
#include "flatpak-table-printer.h"
#include "flatpak-utils.h"
static gboolean opt_user;
static gboolean opt_system;
static char **opt_installations;
static GOptionEntry options[] = {
{ "user", 0, 0, G_OPTION_ARG_NONE, &opt_user, N_("Search only user installations"), NULL },
{ "system", 0, 0, G_OPTION_ARG_NONE, &opt_system, N_("Search only system-wide installations"), NULL },
{ "installation", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_installations, N_("Search specific system-wide installations"), NULL },
{ NULL }
};
static GPtrArray *
get_remote_stores (GPtrArray *dirs, GCancellable *cancellable)
{
@ -219,44 +208,14 @@ print_app (MatchResult *res, FlatpakTablePrinter *printer)
gboolean
flatpak_builtin_search (int argc, char **argv, GCancellable *cancellable, GError **error)
{
g_autoptr(GPtrArray) dirs = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
g_autoptr(GPtrArray) dirs = NULL;
g_autoptr(GOptionContext) context = g_option_context_new (_("TEXT - Search remote apps/runtimes for text"));
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR,
NULL, cancellable, error))
if (!flatpak_option_context_parse (context, NULL, &argc, &argv,
FLATPAK_BUILTIN_FLAG_STANDARD_DIRS, &dirs, cancellable, error))
return FALSE;
// Default: All system and user remotes
if (!opt_user && !opt_system && opt_installations == NULL)
opt_user = opt_system = TRUE;
if (opt_user)
g_ptr_array_add (dirs, flatpak_dir_get_user ());
if (opt_system)
g_ptr_array_add (dirs, flatpak_dir_get_system_default ());
if (opt_installations != NULL)
{
int i = 0;
for (i = 0; opt_installations[i] != NULL; i++)
{
FlatpakDir *installation_dir = NULL;
/* Already included the default system installation. */
if (opt_system && g_strcmp0 (opt_installations[i], "default") == 0)
continue;
installation_dir = flatpak_dir_get_system_by_id (opt_installations[i], cancellable, error);
if (installation_dir == NULL)
return FALSE;
g_ptr_array_add (dirs, installation_dir);
}
}
if (argc < 2)
return usage_error (context, _("TEXT must be specified"), error);
@ -334,11 +293,11 @@ flatpak_complete_search (FlatpakCompletion *completion)
g_autoptr(GOptionContext) context = NULL;
context = g_option_context_new ("");
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL))
if (!flatpak_option_context_parse (context, NULL, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_STANDARD_DIRS, NULL, NULL, NULL))
return FALSE;
flatpak_complete_options (completion, options);
flatpak_complete_options (completion, global_entries);
flatpak_complete_options (completion, user_entries);
return TRUE;
}

View File

@ -54,7 +54,8 @@ gboolean
flatpak_builtin_uninstall (int argc, char **argv, GCancellable *cancellable, GError **error)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
char **prefs = NULL;
int i, j, n_prefs;
const char *default_branch = NULL;
@ -69,9 +70,13 @@ flatpak_builtin_uninstall (int argc, char **argv, GCancellable *cancellable, GEr
context = g_option_context_new (_("REF... - Uninstall an application"));
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
if (!flatpak_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
if (!flatpak_option_context_parse (context, options, &argc, &argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR,
&dirs, cancellable, error))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
if (argc < 2)
return usage_error (context, _("Must specify at least one REF"), error);
@ -169,13 +174,17 @@ gboolean
flatpak_complete_uninstall (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
FlatpakKinds kinds;
context = g_option_context_new ("");
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL))
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR, &dirs, NULL, NULL))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
kinds = flatpak_kinds_from_bools (opt_app, opt_runtime);
switch (completion->argc)

View File

@ -124,7 +124,8 @@ flatpak_builtin_update (int argc,
GError **error)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
char **prefs = NULL;
int i, j, n_prefs;
const char *default_branch = NULL;
@ -134,9 +135,13 @@ flatpak_builtin_update (int argc,
context = g_option_context_new (_("[REF...] - Update applications or runtimes"));
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
if (!flatpak_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
if (!flatpak_option_context_parse (context, options, &argc, &argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR,
&dirs, cancellable, error))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
if (opt_appstream)
return update_appstream (dir, argc >= 2 ? argv[1] : NULL, cancellable, error);
@ -262,13 +267,17 @@ gboolean
flatpak_complete_update (FlatpakCompletion *completion)
{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
FlatpakDir *dir;
FlatpakKinds kinds;
context = g_option_context_new ("");
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, 0, &dir, NULL, NULL))
if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv,
FLATPAK_BUILTIN_FLAG_ONE_DIR, &dirs, NULL, NULL))
return FALSE;
dir = g_ptr_array_index (dirs, 0);
kinds = flatpak_kinds_from_bools (opt_app, opt_runtime);
switch (completion->argc)

View File

@ -32,6 +32,9 @@ G_BEGIN_DECLS
typedef enum {
FLATPAK_BUILTIN_FLAG_NO_DIR = 1 << 0,
FLATPAK_BUILTIN_FLAG_OPTIONAL_REPO = 1 << 1,
FLATPAK_BUILTIN_FLAG_ONE_DIR = 1 << 2,
FLATPAK_BUILTIN_FLAG_STANDARD_DIRS = 1 << 3,
FLATPAK_BUILTIN_FLAG_ALL_DIRS = 1 << 4,
} FlatpakBuiltinFlags;
gboolean flatpak_option_context_parse (GOptionContext *context,
@ -39,7 +42,7 @@ gboolean flatpak_option_context_parse (GOptionContext *context,
int *argc,
char ***argv,
FlatpakBuiltinFlags flags,
FlatpakDir **out_dir,
GPtrArray **out_dirs,
GCancellable *cancellable,
GError **error);

View File

@ -40,7 +40,8 @@ static gboolean opt_default_arch;
static gboolean opt_supported_arches;
static gboolean opt_gl_drivers;
static gboolean opt_user;
static char *opt_installation;
static gboolean opt_system;
static char **opt_installations;
static gboolean is_in_complete;
@ -138,8 +139,8 @@ static GOptionEntry empty_entries[] = {
GOptionEntry user_entries[] = {
{ "user", 0, 0, G_OPTION_ARG_NONE, &opt_user, N_("Work on user installations"), NULL },
{ "system", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &opt_user, N_("Work on system-wide installations (default)"), NULL },
{ "installation", 0, 0, G_OPTION_ARG_STRING, &opt_installation, N_("Work on a specific system-wide installation"), N_("NAME") },
{ "system", 0, 0, G_OPTION_ARG_NONE, &opt_system, N_("Work on system-wide installations (default)"), NULL },
{ "installation", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_installations, N_("Work on specific system-wide installation(s)"), N_("NAME") },
{ NULL }
};
@ -221,11 +222,32 @@ flatpak_option_context_parse (GOptionContext *context,
int *argc,
char ***argv,
FlatpakBuiltinFlags flags,
FlatpakDir **out_dir,
GPtrArray **out_dirs,
GCancellable *cancellable,
GError **error)
{
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GPtrArray) dirs = NULL;
if (!(flags & FLATPAK_BUILTIN_FLAG_NO_DIR) &&
!(flags & FLATPAK_BUILTIN_FLAG_ONE_DIR) &&
!(flags & FLATPAK_BUILTIN_FLAG_STANDARD_DIRS) &&
!(flags & FLATPAK_BUILTIN_FLAG_ALL_DIRS))
g_assert_not_reached ();
if (flags & FLATPAK_BUILTIN_FLAG_NO_DIR &&
(flags & FLATPAK_BUILTIN_FLAG_ONE_DIR ||
flags & FLATPAK_BUILTIN_FLAG_STANDARD_DIRS ||
flags & FLATPAK_BUILTIN_FLAG_ALL_DIRS))
g_assert_not_reached ();
if (flags & FLATPAK_BUILTIN_FLAG_ONE_DIR &&
(flags & FLATPAK_BUILTIN_FLAG_STANDARD_DIRS ||
flags & FLATPAK_BUILTIN_FLAG_ALL_DIRS))
g_assert_not_reached ();
if (flags & FLATPAK_BUILTIN_FLAG_STANDARD_DIRS &&
flags & FLATPAK_BUILTIN_FLAG_ALL_DIRS)
g_assert_not_reached ();
if (!(flags & FLATPAK_BUILTIN_FLAG_NO_DIR))
g_option_context_add_main_entries (context, user_entries, NULL);
@ -282,33 +304,97 @@ flatpak_option_context_parse (GOptionContext *context,
if (!(flags & FLATPAK_BUILTIN_FLAG_NO_DIR))
{
if (opt_user)
dir = flatpak_dir_get_user ();
else if (opt_installation == NULL)
dir = flatpak_dir_get_system_default ();
else
dirs = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
int i;
if (!(flags & FLATPAK_BUILTIN_FLAG_ONE_DIR))
{
dir = flatpak_dir_get_system_by_id (opt_installation, cancellable, error);
if (dir == NULL)
return FALSE;
/*
* FLATPAK_BUILTIN_FLAG_STANDARD_DIRS or FLATPAK_BUILTIN_FLAG_ALL_DIRS
* must be set.
*/
if (opt_user || (!opt_system && opt_installations == NULL))
g_ptr_array_add (dirs, flatpak_dir_get_user ());
if (opt_system || (!opt_user && opt_installations == NULL))
g_ptr_array_add (dirs, flatpak_dir_get_system_default ());
if (opt_installations != NULL)
{
for (i = 0; opt_installations[i] != NULL; i++)
{
FlatpakDir *installation_dir = NULL;
/* Already included the default system installation */
if (opt_system && g_strcmp0 (opt_installations[i], "default") == 0)
continue;
installation_dir = flatpak_dir_get_system_by_id (opt_installations[i], cancellable, error);
if (installation_dir == NULL)
return FALSE;
g_ptr_array_add (dirs, installation_dir);
}
}
if (flags & FLATPAK_BUILTIN_FLAG_ALL_DIRS &&
opt_installations == NULL && !opt_user && !opt_system)
{
g_autoptr(GPtrArray) system_dirs = NULL;
g_ptr_array_set_size (dirs, 0);
g_ptr_array_add (dirs, flatpak_dir_get_user ());
system_dirs = flatpak_dir_get_system_list (cancellable, error);
for (i = 0; i < system_dirs->len; i++)
{
FlatpakDir *dir = g_ptr_array_index (system_dirs, i);
g_ptr_array_add (dirs, g_object_ref (dir));
}
}
}
else /* FLATPAK_BUILTIN_FLAG_ONE_DIR */
{
FlatpakDir *dir;
if (opt_system || (!opt_user && opt_installations == NULL))
dir = flatpak_dir_get_system_default ();
else if (opt_user)
dir = flatpak_dir_get_user ();
else if (opt_installations != NULL)
{
if (g_strv_length (opt_installations) > 1)
return usage_error (context, _("The --installation option was used multiple times"
"for a command that works on one installation"), error);
dir = flatpak_dir_get_system_by_id (opt_installations[0], cancellable, error);
if (dir == NULL)
return FALSE;
}
g_ptr_array_add (dirs, dir);
}
if (flags & FLATPAK_BUILTIN_FLAG_OPTIONAL_REPO)
for (i = 0; i < dirs->len; i++)
{
if (!flatpak_dir_maybe_ensure_repo (dir, cancellable, error))
return FALSE;
}
else
{
if (!flatpak_dir_ensure_repo (dir, cancellable, error))
return FALSE;
}
FlatpakDir *dir = g_ptr_array_index (dirs, i);
flatpak_log_dir_access (dir);
if (flags & FLATPAK_BUILTIN_FLAG_OPTIONAL_REPO)
{
if (!flatpak_dir_maybe_ensure_repo (dir, cancellable, error))
return FALSE;
}
else
{
if (!flatpak_dir_ensure_repo (dir, cancellable, error))
return FALSE;
}
flatpak_log_dir_access (dir);
}
}
if (out_dir)
*out_dir = g_steal_pointer (&dir);
if (out_dirs)
*out_dirs = g_steal_pointer (&dirs);
return TRUE;
}