From e0e23ee181a27686e893ab86f2727010fb3eee4c Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 10 Mar 2015 16:33:56 +0100 Subject: [PATCH] Add make-app-current --- Makefile.am | 1 + completion/xdg-app | 6 +- doc/Makefile.am | 1 + doc/xdg-app-install-app.xml | 5 +- doc/xdg-app-make-app-current.xml | 137 +++++++++++++++++++++++++++++++ xdg-app-builtins-make-current.c | 76 +++++++++++++++++ xdg-app-builtins.h | 1 + xdg-app-main.c | 1 + 8 files changed, 224 insertions(+), 4 deletions(-) create mode 100644 doc/xdg-app-make-app-current.xml create mode 100644 xdg-app-builtins-make-current.c diff --git a/Makefile.am b/Makefile.am index 2b23f7fa..03aee505 100644 --- a/Makefile.am +++ b/Makefile.am @@ -87,6 +87,7 @@ xdg_app_SOURCES = \ xdg-app-builtins-list-remotes.c \ xdg-app-builtins-repo-contents.c \ xdg-app-builtins-install.c \ + xdg-app-builtins-make-current.c \ xdg-app-builtins-update.c \ xdg-app-builtins-uninstall.c \ xdg-app-builtins-list.c \ diff --git a/completion/xdg-app b/completion/xdg-app index 94e0bc85..f0eafa0c 100755 --- a/completion/xdg-app +++ b/completion/xdg-app @@ -15,10 +15,10 @@ _xdg-app() { local dir cmd sdk loc local -A VERBS=( - [ALL]='add-remote delete-remote list-remotes repo-contents install-runtime update-runtime uninstall-runtime list-runtimes install-app update-app uninstall-app list-apps run build-init build build-finish build-export repo-update' - [MODE]='add-remote delete-remote list-remotes repo-contents install-runtime update-runtime uninstall-runtime list-runtimes install-app update-app uninstall-app list-apps' + [ALL]='add-remote delete-remote list-remotes repo-contents install-runtime update-runtime uninstall-runtime list-runtimes install-app update-app uninstall-app list-apps run build-init build build-finish build-export repo-update make-app-current' + [MODE]='add-remote delete-remote list-remotes repo-contents install-runtime update-runtime uninstall-runtime list-runtimes install-app update-app uninstall-app list-apps make-app-current' [UNINSTALL]='uninstall-runtime uninstall-app' - [ARCH]='build-init install-runtime install-app run uninstall-runtime uninstall-app update-runtime update-app' + [ARCH]='build-init install-runtime install-app run uninstall-runtime uninstall-app update-runtime update-app make-app-current' ) local -A OPTS=( diff --git a/doc/Makefile.am b/doc/Makefile.am index e9eac003..c427729a 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -24,6 +24,7 @@ man_MANS = \ xdg-app-list-runtimes.1 \ xdg-app-install-app.1 \ xdg-app-update-app.1 \ + xdg-app-make-app-current.1 \ xdg-app-uninstall-app.1 \ xdg-app-list-apps.1 \ xdg-app-run.1 \ diff --git a/doc/xdg-app-install-app.xml b/doc/xdg-app-install-app.xml index b8ee4c91..725580a3 100644 --- a/doc/xdg-app-install-app.xml +++ b/doc/xdg-app-install-app.xml @@ -49,7 +49,10 @@ Note that xdg-app allows to have multiple branches of an application - installed and used at the same time. + installed and used at the same time. However, only one can be current, + meaning its exported files (for instance desktop files and icons) are + visible to the host. The last installed version is made current by + default, but you can manually change with make-app-current. Unless overridden with the --user option, this command creates a diff --git a/doc/xdg-app-make-app-current.xml b/doc/xdg-app-make-app-current.xml new file mode 100644 index 00000000..eeadd184 --- /dev/null +++ b/doc/xdg-app-make-app-current.xml @@ -0,0 +1,137 @@ + + + + + + + xdg-app make-app-current + xdg-app + + + + Developer + Alexander + Larsson + alexl@redhat.com + + + + + + xdg-app make-app-current + 1 + + + + xdg-app-make-app-current + Make a specific version of an app current + + + + + xdg-app make-app-current + OPTION + APP + BRANCH + + + + + Description + + + Makes a particular branch of an application current. Only the current branch + of an app has its exported files (such as desktop files and icons) made visible + to the host. + + + When a new branch is installed it will automatically be made current, so this + command is often not needed. + + + Unless overridden with the --user option, this command creates a + system-wide installation. + + + + + + Options + + The following options are understood: + + + + + + + + Show help options and exit. + + + + + + + + Create a per-user installation. + + + + + + + + Create a system-wide installation. + + + + + + + + The architecture to install for. + + + + + + + + + Print debug information during command processing. + + + + + + + + Print version information and exit. + + + + + + + Examples + + + $ xdg-app --user make-app-current org.gnome.GEdit 3.14 + + + + + + See also + + + xdg-app1, + xdg-app-install-app1, + xdg-app-list-apps1 + + + + + diff --git a/xdg-app-builtins-make-current.c b/xdg-app-builtins-make-current.c new file mode 100644 index 00000000..b32e8e90 --- /dev/null +++ b/xdg-app-builtins-make-current.c @@ -0,0 +1,76 @@ +#include "config.h" + +#include +#include +#include +#include + +#include "libgsystem.h" + +#include "xdg-app-builtins.h" +#include "xdg-app-utils.h" + +static char *opt_arch; + +static GOptionEntry options[] = { + { "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, "Arch to make current for", "ARCH" }, + { NULL } +}; + +gboolean +xdg_app_builtin_make_current_app (int argc, char **argv, GCancellable *cancellable, GError **error) +{ + gboolean ret = FALSE; + GOptionContext *context; + gs_unref_object XdgAppDir *dir = NULL; + gs_unref_object GFile *deploy_base = NULL; + gs_unref_object GFile *origin = NULL; + const char *app; + const char *branch = "master"; + gs_free char *ref = NULL; + + context = g_option_context_new ("APP BRANCH - Make branch of application current"); + + if (!xdg_app_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error)) + goto out; + + if (argc < 3) + { + usage_error (context, "APP and BRANCH must be specified", error); + goto out; + } + + app = argv[1]; + branch = argv[2]; + + if (!xdg_app_is_valid_name (app)) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "'%s' is not a valid application name", app); + goto out; + } + + if (!xdg_app_is_valid_branch (branch)) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "'%s' is not a valid branch name", branch); + goto out; + } + + ref = xdg_app_build_app_ref (app, branch, opt_arch); + + deploy_base = xdg_app_dir_get_deploy_dir (dir, ref); + if (!g_file_query_exists (deploy_base, cancellable)) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "App %s branch %s is not installed", app, branch); + goto out; + } + + if (!xdg_app_dir_make_current_ref (dir, ref, cancellable, error)) + goto out; + + ret = TRUE; + + out: + if (context) + g_option_context_free (context); + return ret; +} diff --git a/xdg-app-builtins.h b/xdg-app-builtins.h index aa9e229b..ddfb1192 100644 --- a/xdg-app-builtins.h +++ b/xdg-app-builtins.h @@ -37,6 +37,7 @@ BUILTINPROTO(update_runtime); BUILTINPROTO(uninstall_runtime); BUILTINPROTO(list_runtimes); BUILTINPROTO(install_app); +BUILTINPROTO(make_current_app); BUILTINPROTO(update_app); BUILTINPROTO(uninstall_app); BUILTINPROTO(list_apps); diff --git a/xdg-app-main.c b/xdg-app-main.c index edb211ed..b74ed0c2 100644 --- a/xdg-app-main.c +++ b/xdg-app-main.c @@ -29,6 +29,7 @@ static XdgAppCommand commands[] = { { "list-runtimes", xdg_app_builtin_list_runtimes }, { "install-app", xdg_app_builtin_install_app }, { "update-app", xdg_app_builtin_update_app }, + { "make-app-current", xdg_app_builtin_make_current_app }, { "uninstall-app", xdg_app_builtin_uninstall_app }, { "list-apps", xdg_app_builtin_list_apps }, { "run", xdg_app_builtin_run },