2015-03-23 11:17:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2014 Red Hat, Inc
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Alexander Larsson <alexl@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2014-12-18 10:37:30 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "libgsystem.h"
|
2015-03-20 15:21:19 +00:00
|
|
|
#include "libglnx/libglnx.h"
|
2014-12-18 10:37:30 +00:00
|
|
|
|
|
|
|
#include "xdg-app-builtins.h"
|
|
|
|
#include "xdg-app-utils.h"
|
|
|
|
|
|
|
|
static char *opt_arch;
|
2015-01-17 02:51:21 +00:00
|
|
|
static char *opt_commit;
|
2015-02-05 21:31:01 +00:00
|
|
|
static gboolean opt_force_remove;
|
2014-12-18 10:37:30 +00:00
|
|
|
|
|
|
|
static GOptionEntry options[] = {
|
2015-01-14 05:40:21 +00:00
|
|
|
{ "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, "Arch to update for", "ARCH" },
|
2015-01-17 02:51:21 +00:00
|
|
|
{ "commit", 0, 0, G_OPTION_ARG_STRING, &opt_commit, "Commit to deploy", "COMMIT" },
|
2015-02-05 21:31:01 +00:00
|
|
|
{ "force-remove", 0, 0, G_OPTION_ARG_NONE, &opt_force_remove, "Remove old files even if running", NULL },
|
2014-12-18 10:37:30 +00:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
xdg_app_builtin_update_runtime (int argc, char **argv, GCancellable *cancellable, GError **error)
|
|
|
|
{
|
2015-09-28 14:40:19 +00:00
|
|
|
g_autoptr(GOptionContext) context = NULL;
|
2015-03-20 15:21:19 +00:00
|
|
|
g_autoptr(XdgAppDir) dir = NULL;
|
2014-12-18 10:37:30 +00:00
|
|
|
const char *runtime;
|
|
|
|
const char *branch = "master";
|
2015-03-20 15:21:19 +00:00
|
|
|
g_autofree char *previous_deployment = NULL;
|
|
|
|
g_autofree char *ref = NULL;
|
|
|
|
g_autofree char *repository = NULL;
|
2014-12-18 10:37:30 +00:00
|
|
|
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))
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2014-12-18 10:37:30 +00:00
|
|
|
|
2014-12-18 14:26:40 +00:00
|
|
|
if (argc < 2)
|
2015-09-28 14:40:19 +00:00
|
|
|
return usage_error (context, "RUNTIME must be specified", error);
|
2014-12-18 10:37:30 +00:00
|
|
|
|
2014-12-18 14:26:40 +00:00
|
|
|
runtime = argv[1];
|
2014-12-18 10:37:30 +00:00
|
|
|
if (argc >= 3)
|
|
|
|
branch = argv[2];
|
|
|
|
|
2015-02-11 11:39:17 +00:00
|
|
|
if (!xdg_app_is_valid_name (runtime))
|
2015-09-28 14:54:24 +00:00
|
|
|
return xdg_app_fail (error, "'%s' is not a valid runtime name", runtime);
|
2015-02-11 11:39:17 +00:00
|
|
|
|
|
|
|
if (!xdg_app_is_valid_branch (branch))
|
2015-09-28 14:54:24 +00:00
|
|
|
return xdg_app_fail (error, "'%s' is not a valid branch name", branch);
|
2015-02-11 11:39:17 +00:00
|
|
|
|
2014-12-18 10:37:30 +00:00
|
|
|
ref = xdg_app_build_runtime_ref (runtime, branch, opt_arch);
|
|
|
|
|
2015-06-01 11:28:03 +00:00
|
|
|
repository = xdg_app_dir_get_origin (dir, ref, cancellable, error);
|
|
|
|
if (repository == NULL)
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2014-12-18 10:37:30 +00:00
|
|
|
|
2015-12-15 11:26:59 +00:00
|
|
|
if (!xdg_app_dir_pull (dir, repository, ref, NULL,
|
2014-12-18 10:37:30 +00:00
|
|
|
cancellable, error))
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2014-12-18 10:37:30 +00:00
|
|
|
|
2014-12-19 10:21:47 +00:00
|
|
|
previous_deployment = xdg_app_dir_read_active (dir, ref, cancellable);
|
2014-12-19 10:18:27 +00:00
|
|
|
|
2014-12-18 10:37:30 +00:00
|
|
|
my_error = NULL;
|
2015-01-17 02:51:21 +00:00
|
|
|
if (!xdg_app_dir_deploy (dir, ref, opt_commit, cancellable, &my_error))
|
2014-12-18 10:37:30 +00:00
|
|
|
{
|
|
|
|
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);
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2014-12-18 10:37:30 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-16 14:33:52 +00:00
|
|
|
else
|
2014-12-19 10:18:27 +00:00
|
|
|
{
|
2015-06-16 14:33:52 +00:00
|
|
|
if (previous_deployment != NULL)
|
|
|
|
{
|
|
|
|
if (!xdg_app_dir_undeploy (dir, ref, previous_deployment,
|
|
|
|
opt_force_remove,
|
|
|
|
cancellable, error))
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2014-12-19 10:18:27 +00:00
|
|
|
|
2015-06-16 14:33:52 +00:00
|
|
|
if (!xdg_app_dir_prune (dir, cancellable, error))
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2015-06-16 14:33:52 +00:00
|
|
|
}
|
2014-12-19 10:18:27 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 11:43:22 +00:00
|
|
|
xdg_app_dir_cleanup_removed (dir, cancellable, NULL);
|
|
|
|
|
2015-09-28 14:40:19 +00:00
|
|
|
return TRUE;
|
2014-12-18 10:37:30 +00:00
|
|
|
}
|
2014-12-18 14:26:40 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
xdg_app_builtin_update_app (int argc, char **argv, GCancellable *cancellable, GError **error)
|
|
|
|
{
|
2015-09-28 14:40:19 +00:00
|
|
|
g_autoptr(GOptionContext) context = NULL;
|
2015-03-20 15:21:19 +00:00
|
|
|
g_autoptr(XdgAppDir) dir = NULL;
|
2014-12-18 14:26:40 +00:00
|
|
|
const char *app;
|
|
|
|
const char *branch = "master";
|
2015-03-20 15:21:19 +00:00
|
|
|
g_autofree char *ref = NULL;
|
|
|
|
g_autofree char *repository = NULL;
|
|
|
|
g_autofree char *previous_deployment = NULL;
|
2014-12-18 14:26:40 +00:00
|
|
|
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))
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2014-12-18 14:26:40 +00:00
|
|
|
|
|
|
|
if (argc < 2)
|
2015-09-28 14:40:19 +00:00
|
|
|
return usage_error (context, "APP must be specified", error);
|
2014-12-18 14:26:40 +00:00
|
|
|
|
|
|
|
app = argv[1];
|
|
|
|
if (argc >= 3)
|
|
|
|
branch = argv[2];
|
|
|
|
|
2015-02-11 11:39:17 +00:00
|
|
|
if (!xdg_app_is_valid_name (app))
|
2015-09-28 14:54:24 +00:00
|
|
|
return xdg_app_fail (error, "'%s' is not a valid application name", app);
|
2015-02-11 11:39:17 +00:00
|
|
|
|
|
|
|
if (!xdg_app_is_valid_branch (branch))
|
2015-09-28 14:54:24 +00:00
|
|
|
return xdg_app_fail (error, "'%s' is not a valid branch name", branch);
|
2015-02-11 11:39:17 +00:00
|
|
|
|
2014-12-18 14:26:40 +00:00
|
|
|
ref = xdg_app_build_app_ref (app, branch, opt_arch);
|
|
|
|
|
2015-06-01 11:28:03 +00:00
|
|
|
repository = xdg_app_dir_get_origin (dir, ref, cancellable, error);
|
|
|
|
if (repository == NULL)
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2014-12-18 14:26:40 +00:00
|
|
|
|
2015-12-15 11:26:59 +00:00
|
|
|
if (!xdg_app_dir_pull (dir, repository, ref, NULL,
|
2014-12-18 14:26:40 +00:00
|
|
|
cancellable, error))
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2014-12-18 14:26:40 +00:00
|
|
|
|
2014-12-19 10:21:47 +00:00
|
|
|
previous_deployment = xdg_app_dir_read_active (dir, ref, cancellable);
|
2014-12-19 10:18:27 +00:00
|
|
|
|
2014-12-18 14:26:40 +00:00
|
|
|
my_error = NULL;
|
2015-01-17 02:51:21 +00:00
|
|
|
if (!xdg_app_dir_deploy (dir, ref, opt_commit, cancellable, &my_error))
|
2014-12-18 14:26:40 +00:00
|
|
|
{
|
|
|
|
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);
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2014-12-18 14:26:40 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-16 14:33:52 +00:00
|
|
|
else
|
2014-12-19 10:18:27 +00:00
|
|
|
{
|
2015-06-16 14:33:52 +00:00
|
|
|
if (previous_deployment != NULL)
|
|
|
|
{
|
|
|
|
if (!xdg_app_dir_undeploy (dir, ref, previous_deployment,
|
|
|
|
opt_force_remove,
|
|
|
|
cancellable, error))
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2015-06-16 14:33:52 +00:00
|
|
|
|
|
|
|
if (!xdg_app_dir_prune (dir, cancellable, error))
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2015-06-16 14:33:52 +00:00
|
|
|
}
|
2014-12-19 10:18:27 +00:00
|
|
|
|
2015-06-16 14:33:52 +00:00
|
|
|
if (!xdg_app_dir_update_exports (dir, app, cancellable, error))
|
2015-09-28 14:40:19 +00:00
|
|
|
return FALSE;
|
2014-12-19 10:18:27 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 11:43:22 +00:00
|
|
|
xdg_app_dir_cleanup_removed (dir, cancellable, NULL);
|
|
|
|
|
2015-09-28 14:40:19 +00:00
|
|
|
return TRUE;
|
2014-12-18 14:26:40 +00:00
|
|
|
}
|