Use xdg_app_compose_ref helper

tingping/wmclass
Alexander Larsson 2015-12-15 14:58:12 +01:00
parent b820249178
commit 604f71937a
6 changed files with 38 additions and 134 deletions

View File

@ -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))

View File

@ -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))

View File

@ -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)

View File

@ -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);

View File

@ -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)

View File

@ -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)