Add update-runtime

tingping/wmclass
Alexander Larsson 2014-12-18 11:37:30 +01:00
parent 06e57a081d
commit 3775ae51e2
4 changed files with 94 additions and 0 deletions

View File

@ -16,6 +16,7 @@ xdg_app_SOURCES = \
xdg-app-builtins.h \
xdg-app-builtins-add-repo.c \
xdg-app-builtins-install.c \
xdg-app-builtins-update.c \
xdg-app-dir.c \
xdg-app-dir.h \
xdg-app-utils.h \

View File

@ -0,0 +1,91 @@
#include "config.h"
#include <locale.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#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 update for", NULL },
{ NULL }
};
static void
usage_error (GOptionContext *context, const char *message, GError **error)
{
gs_free gchar *help = g_option_context_get_help (context, TRUE, NULL);
g_printerr ("%s", help);
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, message);
}
gboolean
xdg_app_builtin_update_runtime (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 *runtime;
const char *branch = "master";
gs_free char *ref = NULL;
gs_free char *repository = NULL;
GError *my_error;
context = g_option_context_new ("RUNTIME [BRANCH] - Update a runtime");
if (!xdg_app_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
goto out;
if (argc < 3)
{
usage_error (context, "REPOSITORY and RUNTIME must be specified", error);
goto out;
}
runtime = argv[1];
if (argc >= 3)
branch = argv[2];
ref = xdg_app_build_runtime_ref (runtime, 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, "Runtime %s branch %s not installed", runtime, 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;
}

View File

@ -26,6 +26,7 @@ gboolean xdg_app_option_context_parse (GOptionContext *context,
BUILTINPROTO(add_repo);
BUILTINPROTO(install_runtime);
BUILTINPROTO(update_runtime);
#undef BUILTINPROTO

View File

@ -21,6 +21,7 @@ typedef struct {
static XdgAppCommand commands[] = {
{ "add-repo", xdg_app_builtin_add_repo },
{ "install-runtime", xdg_app_builtin_install_runtime },
{ "update-runtime", xdg_app_builtin_update_runtime },
{ NULL }
};