forked from Mirrors/flatpak-builder
Add app install/update
parent
3775ae51e2
commit
3b53ae6489
|
@ -90,3 +90,69 @@ xdg_app_builtin_install_runtime (int argc, char **argv, GCancellable *cancellabl
|
||||||
g_option_context_free (context);
|
g_option_context_free (context);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
xdg_app_builtin_install_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 *repository;
|
||||||
|
const char *app;
|
||||||
|
const char *branch = "master";
|
||||||
|
gs_free char *ref = NULL;
|
||||||
|
gboolean created_deploy_base = FALSE;
|
||||||
|
|
||||||
|
context = g_option_context_new ("REPOSITORY APP [BRANCH] - Install an application");
|
||||||
|
|
||||||
|
if (!xdg_app_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (argc < 3)
|
||||||
|
{
|
||||||
|
usage_error (context, "REPOSITORY and APP must be specified", error);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
repository = argv[1];
|
||||||
|
app = argv[2];
|
||||||
|
if (argc >= 4)
|
||||||
|
branch = argv[3];
|
||||||
|
|
||||||
|
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 already installed", app, branch);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!xdg_app_dir_pull (dir, repository, ref,
|
||||||
|
cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (!g_file_make_directory_with_parents (deploy_base, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
created_deploy_base = TRUE;
|
||||||
|
|
||||||
|
origin = g_file_get_child (deploy_base, "origin");
|
||||||
|
if (!g_file_replace_contents (origin, repository, strlen (repository), NULL, FALSE,
|
||||||
|
G_FILE_CREATE_NONE, NULL, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (!xdg_app_dir_deploy (dir, ref, NULL, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (created_deploy_base && !ret)
|
||||||
|
gs_shutil_rm_rf (deploy_base, cancellable, NULL);
|
||||||
|
|
||||||
|
if (context)
|
||||||
|
g_option_context_free (context);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
@ -44,13 +44,13 @@ xdg_app_builtin_update_runtime (int argc, char **argv, GCancellable *cancellable
|
||||||
if (!xdg_app_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
|
if (!xdg_app_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (argc < 3)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
usage_error (context, "REPOSITORY and RUNTIME must be specified", error);
|
usage_error (context, "RUNTIME must be specified", error);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime = argv[1];
|
runtime = argv[1];
|
||||||
if (argc >= 3)
|
if (argc >= 3)
|
||||||
branch = argv[2];
|
branch = argv[2];
|
||||||
|
|
||||||
|
@ -89,3 +89,68 @@ xdg_app_builtin_update_runtime (int argc, char **argv, GCancellable *cancellable
|
||||||
g_option_context_free (context);
|
g_option_context_free (context);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
xdg_app_builtin_update_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;
|
||||||
|
gs_free char *repository = NULL;
|
||||||
|
GError *my_error;
|
||||||
|
|
||||||
|
context = g_option_context_new ("APP [BRANCH] - Update an application");
|
||||||
|
|
||||||
|
if (!xdg_app_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (argc < 2)
|
||||||
|
{
|
||||||
|
usage_error (context, "APP must be specified", error);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
app = argv[1];
|
||||||
|
if (argc >= 3)
|
||||||
|
branch = argv[2];
|
||||||
|
|
||||||
|
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 not installed", app, branch);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
origin = g_file_get_child (deploy_base, "origin");
|
||||||
|
if (!g_file_load_contents (origin, cancellable, &repository, NULL, NULL, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (!xdg_app_dir_pull (dir, repository, ref,
|
||||||
|
cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
my_error = NULL;
|
||||||
|
if (!xdg_app_dir_deploy (dir, ref, NULL, cancellable, &my_error))
|
||||||
|
{
|
||||||
|
if (g_error_matches (my_error, XDG_APP_DIR_ERROR, XDG_APP_DIR_ERROR_ALREADY_DEPLOYED))
|
||||||
|
g_error_free (my_error);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_propagate_error (error, my_error);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
out:
|
||||||
|
if (context)
|
||||||
|
g_option_context_free (context);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ gboolean xdg_app_option_context_parse (GOptionContext *context,
|
||||||
BUILTINPROTO(add_repo);
|
BUILTINPROTO(add_repo);
|
||||||
BUILTINPROTO(install_runtime);
|
BUILTINPROTO(install_runtime);
|
||||||
BUILTINPROTO(update_runtime);
|
BUILTINPROTO(update_runtime);
|
||||||
|
BUILTINPROTO(install_app);
|
||||||
|
BUILTINPROTO(update_app);
|
||||||
|
|
||||||
#undef BUILTINPROTO
|
#undef BUILTINPROTO
|
||||||
|
|
||||||
|
|
|
@ -149,6 +149,16 @@ xdg_app_dir_get_deploy_dir (XdgAppDir *self,
|
||||||
return g_file_resolve_relative_path (self->basedir, ref);
|
return g_file_resolve_relative_path (self->basedir, ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GFile *
|
||||||
|
xdg_app_dir_get_app_data (XdgAppDir *self,
|
||||||
|
const char *app)
|
||||||
|
{
|
||||||
|
gs_free char *partial_ref = NULL;
|
||||||
|
|
||||||
|
partial_ref = g_build_filename ("app", app, "data", NULL);
|
||||||
|
return g_file_resolve_relative_path (self->basedir, partial_ref);
|
||||||
|
}
|
||||||
|
|
||||||
OstreeRepo *
|
OstreeRepo *
|
||||||
xdg_app_dir_get_repo (XdgAppDir *self)
|
xdg_app_dir_get_repo (XdgAppDir *self)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,6 +31,8 @@ gboolean xdg_app_dir_is_user (XdgAppDir *self);
|
||||||
GFile * xdg_app_dir_get_path (XdgAppDir *self);
|
GFile * xdg_app_dir_get_path (XdgAppDir *self);
|
||||||
GFile * xdg_app_dir_get_deploy_dir (XdgAppDir *self,
|
GFile * xdg_app_dir_get_deploy_dir (XdgAppDir *self,
|
||||||
const char *ref);
|
const char *ref);
|
||||||
|
GFile * xdg_app_dir_get_app_data (XdgAppDir *self,
|
||||||
|
const char *app);
|
||||||
OstreeRepo *xdg_app_dir_get_repo (XdgAppDir *self);
|
OstreeRepo *xdg_app_dir_get_repo (XdgAppDir *self);
|
||||||
gboolean xdg_app_dir_ensure_path (XdgAppDir *self,
|
gboolean xdg_app_dir_ensure_path (XdgAppDir *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
|
|
@ -22,6 +22,8 @@ static XdgAppCommand commands[] = {
|
||||||
{ "add-repo", xdg_app_builtin_add_repo },
|
{ "add-repo", xdg_app_builtin_add_repo },
|
||||||
{ "install-runtime", xdg_app_builtin_install_runtime },
|
{ "install-runtime", xdg_app_builtin_install_runtime },
|
||||||
{ "update-runtime", xdg_app_builtin_update_runtime },
|
{ "update-runtime", xdg_app_builtin_update_runtime },
|
||||||
|
{ "install-app", xdg_app_builtin_install_app },
|
||||||
|
{ "update-app", xdg_app_builtin_update_app },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue