Redo list commands

Make it so that one can specify --user or --system to list
only items from one location, but if neither is specified,
both user and system items are listed.
This commit is contained in:
Matthias Clasen committed 2015-01-23 07:40:25 -05:00
1 parent 8328d851ad
commit bd8b8232fc
1 file changed
+40 -19
+40 -19
View File
@@ -11,22 +11,31 @@
#include "xdg-app-utils.h"
static gboolean opt_show_details;
static gboolean opt_user;
static gboolean opt_system;
static GOptionEntry options[] = {
{ "user", 0, 0, G_OPTION_ARG_NONE, &opt_user, "Show user installations", NULL },
{ "system", 0, 0, G_OPTION_ARG_NONE, &opt_system, "Show system-wide installations", NULL },
{ "show-details", 0, 0, G_OPTION_ARG_NONE, &opt_show_details, "Show arches and branches", NULL },
{ NULL }
};
static gboolean
print_installed_refs (GFile *base, GCancellable *cancellable, GError **error)
print_installed_refs (XdgAppDir *dir, const char *kind, GCancellable *cancellable, GError **error)
{
gboolean ret = FALSE;
gs_unref_object GFile *base;
gs_unref_object GFileEnumerator *dir_enum = NULL;
gs_unref_object GFileInfo *child_info = NULL;
GError *temp_error = NULL;
gs_unref_ptrarray GPtrArray *refs = NULL;
int i;
base = g_file_get_child (xdg_app_dir_get_path (dir), kind);
if (!g_file_query_exists (base, cancellable))
return TRUE;
refs = g_ptr_array_new ();
dir_enum = g_file_enumerate_children (base, G_FILE_ATTRIBUTE_STANDARD_NAME,
@@ -134,23 +143,29 @@ xdg_app_builtin_list_runtimes (int argc, char **argv, GCancellable *cancellable,
{
gboolean ret = FALSE;
GOptionContext *context;
gs_unref_object XdgAppDir *dir = NULL;
gs_unref_object GFile *base = NULL;
context = g_option_context_new (" - List installed runtimes");
if (!xdg_app_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
if (!xdg_app_option_context_parse (context, options, &argc, &argv, XDG_APP_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error))
goto out;
base = g_file_get_child (xdg_app_dir_get_path (dir), "runtime");
if (!g_file_query_exists (base, cancellable))
if (opt_user || (!opt_user && !opt_system))
{
ret = TRUE;
goto out;
gs_unref_object XdgAppDir *dir = NULL;
dir = xdg_app_dir_get (TRUE);
if (!print_installed_refs (dir, "runtime", cancellable, error))
goto out;
}
if (!print_installed_refs (base, cancellable, error))
goto out;
if (opt_system || (!opt_user && !opt_system))
{
gs_unref_object XdgAppDir *dir = NULL;
dir = xdg_app_dir_get (FALSE);
if (!print_installed_refs (dir, "runtime", cancellable, error))
goto out;
}
ret = TRUE;
@@ -167,23 +182,29 @@ xdg_app_builtin_list_apps (int argc, char **argv, GCancellable *cancellable, GEr
{
gboolean ret = FALSE;
GOptionContext *context;
gs_unref_object XdgAppDir *dir = NULL;
gs_unref_object GFile *base = NULL;
context = g_option_context_new (" - List installed applications");
if (!xdg_app_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
if (!xdg_app_option_context_parse (context, options, &argc, &argv, XDG_APP_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error))
goto out;
base = g_file_get_child (xdg_app_dir_get_path (dir), "app");
if (!g_file_query_exists (base, cancellable))
if (opt_user || (!opt_user && !opt_system))
{
ret = TRUE;
goto out;
gs_unref_object XdgAppDir *dir = NULL;
dir = xdg_app_dir_get (TRUE);
if (!print_installed_refs (dir, "app", cancellable, error))
goto out;
}
if (!print_installed_refs (base, cancellable, error))
goto out;
if (opt_system || (!opt_user && !opt_system))
{
gs_unref_object XdgAppDir *dir = NULL;
dir = xdg_app_dir_get (FALSE);
if (!print_installed_refs (dir, "app", cancellable, error))
goto out;
}
ret = TRUE;