From 604f71937ac1d0d5aea090876280f99294301ba6 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 15 Dec 2015 14:58:12 +0100 Subject: [PATCH] Use xdg_app_compose_ref helper --- app/xdg-app-builtins-install.c | 36 +++++---------------- app/xdg-app-builtins-make-current.c | 10 ++---- app/xdg-app-builtins-run.c | 10 ++---- app/xdg-app-builtins-uninstall.c | 42 ++++++------------------ app/xdg-app-builtins-update.c | 24 +++++--------- lib/xdg-app-installation.c | 50 ++++------------------------- 6 files changed, 38 insertions(+), 134 deletions(-) diff --git a/app/xdg-app-builtins-install.c b/app/xdg-app-builtins-install.c index a463bdae..bd08793b 100644 --- a/app/xdg-app-builtins-install.c +++ b/app/xdg-app-builtins-install.c @@ -103,7 +103,7 @@ xdg_app_builtin_install_runtime (int argc, char **argv, GCancellable *cancellabl g_autoptr(GFile) deploy_base = NULL; const char *repository; const char *runtime; - const char *branch = "master"; + const char *branch = NULL; g_autofree char *ref = NULL; gboolean created_deploy_base = FALSE; @@ -123,19 +123,9 @@ xdg_app_builtin_install_runtime (int argc, char **argv, GCancellable *cancellabl if (argc >= 4) branch = argv[3]; - if (!xdg_app_is_valid_name (runtime)) - { - xdg_app_fail (error, "'%s' is not a valid runtime name", runtime); - goto out; - } - - if (!xdg_app_is_valid_branch (branch)) - { - xdg_app_fail (error, "'%s' is not a valid branch name", branch); - goto out; - } - - ref = xdg_app_build_runtime_ref (runtime, branch, opt_arch); + ref = xdg_app_compose_ref (FALSE, runtime, branch, opt_arch, error); + if (ref == NULL) + goto out; deploy_base = xdg_app_dir_get_deploy_dir (dir, ref); if (g_file_query_exists (deploy_base, cancellable)) @@ -178,7 +168,7 @@ xdg_app_builtin_install_app (int argc, char **argv, GCancellable *cancellable, G g_autoptr(GFile) deploy_base = NULL; const char *repository; const char *app; - const char *branch = "master"; + const char *branch = NULL; g_autofree char *ref = NULL; gboolean created_deploy_base = FALSE; @@ -198,19 +188,9 @@ xdg_app_builtin_install_app (int argc, char **argv, GCancellable *cancellable, G if (argc >= 4) branch = argv[3]; - if (!xdg_app_is_valid_name (app)) - { - xdg_app_fail (error, "'%s' is not a valid application name", app); - goto out; - } - - if (!xdg_app_is_valid_branch (branch)) - { - xdg_app_fail (error, "'%s' is not a valid branch name", branch); - goto out; - } - - ref = xdg_app_build_app_ref (app, branch, opt_arch); + ref = xdg_app_compose_ref (TRUE, app, branch, opt_arch, error); + if (ref == NULL) + goto out; deploy_base = xdg_app_dir_get_deploy_dir (dir, ref); if (g_file_query_exists (deploy_base, cancellable)) diff --git a/app/xdg-app-builtins-make-current.c b/app/xdg-app-builtins-make-current.c index 2f0d23bf..9006472b 100644 --- a/app/xdg-app-builtins-make-current.c +++ b/app/xdg-app-builtins-make-current.c @@ -59,13 +59,9 @@ xdg_app_builtin_make_current_app (int argc, char **argv, GCancellable *cancellab app = argv[1]; branch = argv[2]; - if (!xdg_app_is_valid_name (app)) - return xdg_app_fail (error, "'%s' is not a valid application name", app); - - if (!xdg_app_is_valid_branch (branch)) - return xdg_app_fail (error, "'%s' is not a valid branch name", branch); - - ref = xdg_app_build_app_ref (app, branch, opt_arch); + ref = xdg_app_compose_ref (TRUE, app, branch, opt_arch, error); + if (ref == NULL) + return FALSE; deploy_base = xdg_app_dir_get_deploy_dir (dir, ref); if (!g_file_query_exists (deploy_base, cancellable)) diff --git a/app/xdg-app-builtins-run.c b/app/xdg-app-builtins-run.c index e65eedd0..87ebcd87 100644 --- a/app/xdg-app-builtins-run.c +++ b/app/xdg-app-builtins-run.c @@ -91,13 +91,9 @@ xdg_app_builtin_run (int argc, char **argv, GCancellable *cancellable, GError ** if (opt_branch) branch = opt_branch; - if (!xdg_app_is_valid_name (app)) - return xdg_app_fail (error, "'%s' is not a valid application name", app); - - if (!xdg_app_is_valid_branch (branch)) - return xdg_app_fail (error, "'%s' is not a valid branch name", branch); - - app_ref = xdg_app_build_app_ref (app, branch, opt_arch); + app_ref = xdg_app_compose_ref (TRUE, app, branch, opt_arch, error); + if (app_ref == NULL) + return FALSE; app_deploy = xdg_app_find_deploy_for_ref (app_ref, cancellable, error); if (app_deploy == NULL) diff --git a/app/xdg-app-builtins-uninstall.c b/app/xdg-app-builtins-uninstall.c index 46f096a7..c85d252f 100644 --- a/app/xdg-app-builtins-uninstall.c +++ b/app/xdg-app-builtins-uninstall.c @@ -47,9 +47,8 @@ xdg_app_builtin_uninstall_runtime (int argc, char **argv, GCancellable *cancella { g_autoptr(GOptionContext) context = NULL; g_autoptr(XdgAppDir) dir = NULL; - const char *name; - const char *arch; - const char *branch; + const char *name = NULL; + const char *branch = NULL; g_autofree char *ref = NULL; g_autofree char *repository = NULL; gboolean was_deployed; @@ -65,23 +64,13 @@ xdg_app_builtin_uninstall_runtime (int argc, char **argv, GCancellable *cancella name = argv[1]; if (argc > 2) branch = argv[2]; - else - branch = "master"; - if (opt_arch) - arch = opt_arch; - else - arch = xdg_app_get_arch (); - if (!xdg_app_is_valid_name (name)) - return xdg_app_fail (error, "'%s' is not a valid runtime name", name); - - if (!xdg_app_is_valid_branch (branch)) - return xdg_app_fail (error, "'%s' is not a valid branch name", branch); + ref = xdg_app_compose_ref (FALSE, name, branch, opt_arch, error); + if (ref == NULL) + return FALSE; /* TODO: look for apps, require --force */ - ref = g_build_filename ("runtime", name, arch, branch, NULL); - repository = xdg_app_dir_get_origin (dir, ref, cancellable, NULL); g_debug ("dropping active ref"); @@ -113,9 +102,8 @@ xdg_app_builtin_uninstall_app (int argc, char **argv, GCancellable *cancellable, { g_autoptr(GOptionContext) context = NULL; g_autoptr(XdgAppDir) dir = NULL; - const char *name; - const char *arch; - const char *branch; + const char *name = NULL; + const char *branch = NULL; g_autofree char *ref = NULL; g_autofree char *repository = NULL; g_autofree char *current_ref = NULL; @@ -132,20 +120,10 @@ xdg_app_builtin_uninstall_app (int argc, char **argv, GCancellable *cancellable, name = argv[1]; if (argc > 2) branch = argv[2]; - else - branch = "master"; - if (opt_arch) - arch = opt_arch; - else - arch = xdg_app_get_arch (); - if (!xdg_app_is_valid_name (name)) - return xdg_app_fail (error, "'%s' is not a valid application name", name); - - if (!xdg_app_is_valid_branch (branch)) - return xdg_app_fail (error, "'%s' is not a valid branch name", branch); - - ref = g_build_filename ("app", name, arch, branch, NULL); + ref = xdg_app_compose_ref (TRUE, name, branch, opt_arch, error); + if (ref == NULL) + return FALSE; repository = xdg_app_dir_get_origin (dir, ref, cancellable, NULL); diff --git a/app/xdg-app-builtins-update.c b/app/xdg-app-builtins-update.c index 709bd049..348ff5cd 100644 --- a/app/xdg-app-builtins-update.c +++ b/app/xdg-app-builtins-update.c @@ -48,7 +48,7 @@ xdg_app_builtin_update_runtime (int argc, char **argv, GCancellable *cancellable g_autoptr(GOptionContext) context = NULL; g_autoptr(XdgAppDir) dir = NULL; const char *runtime; - const char *branch = "master"; + const char *branch = NULL; g_autofree char *previous_deployment = NULL; g_autofree char *ref = NULL; g_autofree char *repository = NULL; @@ -66,13 +66,9 @@ xdg_app_builtin_update_runtime (int argc, char **argv, GCancellable *cancellable if (argc >= 3) branch = argv[2]; - if (!xdg_app_is_valid_name (runtime)) - return xdg_app_fail (error, "'%s' is not a valid runtime name", runtime); - - if (!xdg_app_is_valid_branch (branch)) - return xdg_app_fail (error, "'%s' is not a valid branch name", branch); - - ref = xdg_app_build_runtime_ref (runtime, branch, opt_arch); + ref = xdg_app_compose_ref (FALSE, runtime, branch, opt_arch, error); + if (ref == NULL) + return FALSE; repository = xdg_app_dir_get_origin (dir, ref, cancellable, error); if (repository == NULL) @@ -120,7 +116,7 @@ xdg_app_builtin_update_app (int argc, char **argv, GCancellable *cancellable, GE g_autoptr(GOptionContext) context = NULL; g_autoptr(XdgAppDir) dir = NULL; const char *app; - const char *branch = "master"; + const char *branch = NULL; g_autofree char *ref = NULL; g_autofree char *repository = NULL; g_autofree char *previous_deployment = NULL; @@ -138,13 +134,9 @@ xdg_app_builtin_update_app (int argc, char **argv, GCancellable *cancellable, GE if (argc >= 3) branch = argv[2]; - if (!xdg_app_is_valid_name (app)) - return xdg_app_fail (error, "'%s' is not a valid application name", app); - - if (!xdg_app_is_valid_branch (branch)) - return xdg_app_fail (error, "'%s' is not a valid branch name", branch); - - ref = xdg_app_build_app_ref (app, branch, opt_arch); + ref = xdg_app_compose_ref (TRUE, app, branch, opt_arch, error); + if (ref == NULL) + return FALSE; repository = xdg_app_dir_get_origin (dir, ref, cancellable, error); if (repository == NULL) diff --git a/lib/xdg-app-installation.c b/lib/xdg-app-installation.c index 5773f4a5..ee3bbd09 100644 --- a/lib/xdg-app-installation.c +++ b/lib/xdg-app-installation.c @@ -483,28 +483,9 @@ xdg_app_installation_install (XdgAppInstallation *self, g_autoptr(OstreeAsyncProgress) ostree_progress = NULL; XdgAppInstalledRef *result = NULL; - if (version == NULL) - version = "master"; - - if (arch == NULL) - arch = xdg_app_get_arch (); - - if (!xdg_app_is_valid_name (name)) - { - xdg_app_fail (error, "'%s' is not a valid name", name); - return NULL; - } - - if (!xdg_app_is_valid_branch (version)) - { - xdg_app_fail (error, "'%s' is not a valid branch name", version); - return NULL; - } - - if (kind == XDG_APP_REF_KIND_APP) - ref = xdg_app_build_app_ref (name, version, arch); - else - ref = xdg_app_build_runtime_ref (name, version, arch); + ref = xdg_app_compose_ref (kind == XDG_APP_REF_KIND_APP, name, version, arch, error); + if (ref == NULL) + return NULL; deploy_base = xdg_app_dir_get_deploy_dir (priv->dir, ref); if (g_file_query_exists (deploy_base, cancellable)) @@ -596,28 +577,9 @@ xdg_app_installation_update (XdgAppInstallation *self, XdgAppInstalledRef *result = NULL; g_autoptr(GError) my_error = NULL; - if (version == NULL) - version = "master"; - - if (arch == NULL) - arch = xdg_app_get_arch (); - - if (!xdg_app_is_valid_name (name)) - { - xdg_app_fail (error, "'%s' is not a valid name", name); - return NULL; - } - - if (!xdg_app_is_valid_branch (version)) - { - xdg_app_fail (error, "'%s' is not a valid branch name", version); - return NULL; - } - - if (kind == XDG_APP_REF_KIND_APP) - ref = xdg_app_build_app_ref (name, version, arch); - else - ref = xdg_app_build_runtime_ref (name, version, arch); + ref = xdg_app_compose_ref (kind == XDG_APP_REF_KIND_APP, name, version, arch, error); + if (ref == NULL) + return NULL; remote_name = xdg_app_dir_get_origin (priv->dir, ref, cancellable, error); if (remote_name == NULL)