|
rpm-build |
0fba15 |
/*
|
|
rpm-build |
0fba15 |
* Copyright (C) 2013 Stef Walter <stefw@redhat.com>
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* SPDX-License-Identifier: LGPL-2.0+
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* This library is free software; you can redistribute it and/or
|
|
rpm-build |
0fba15 |
* modify it under the terms of the GNU Lesser General Public
|
|
rpm-build |
0fba15 |
* License as published by the Free Software Foundation; either
|
|
rpm-build |
0fba15 |
* version 2 of the License, or (at your option) any later version.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* This library is distributed in the hope that it will be useful,
|
|
rpm-build |
0fba15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
rpm-build |
0fba15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
rpm-build |
0fba15 |
* Lesser General Public License for more details.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* You should have received a copy of the GNU Lesser General Public
|
|
rpm-build |
0fba15 |
* License along with this library; if not, write to the
|
|
rpm-build |
0fba15 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
rpm-build |
0fba15 |
* Boston, MA 02111-1307, USA.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* Author: Stef Walter <stefw@redhat.com>
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include "config.h"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include "ot-main.h"
|
|
rpm-build |
0fba15 |
#include "ot-builtins.h"
|
|
rpm-build |
0fba15 |
#include "ostree.h"
|
|
rpm-build |
0fba15 |
#include "otutil.h"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* ATTENTION:
|
|
rpm-build |
0fba15 |
* Please remember to update the bash-completion script (bash/ostree) and
|
|
rpm-build |
0fba15 |
* man page (man/ostree-reset.xml) when changing the option list.
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static GOptionEntry options[] = {
|
|
rpm-build |
0fba15 |
{ NULL }
|
|
rpm-build |
0fba15 |
};
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
gboolean
|
|
rpm-build |
0fba15 |
ostree_builtin_reset (int argc,
|
|
rpm-build |
0fba15 |
char **argv,
|
|
rpm-build |
0fba15 |
OstreeCommandInvocation *invocation,
|
|
rpm-build |
0fba15 |
GCancellable *cancellable,
|
|
rpm-build |
0fba15 |
GError **error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autoptr(GOptionContext) context = NULL;
|
|
rpm-build |
0fba15 |
g_autoptr(OstreeRepo) repo = NULL;
|
|
rpm-build |
0fba15 |
g_autoptr(GHashTable) known_refs = NULL;
|
|
rpm-build |
0fba15 |
gboolean ret = FALSE;
|
|
rpm-build |
0fba15 |
const char *ref;
|
|
rpm-build |
0fba15 |
const char *target = NULL;
|
|
rpm-build |
0fba15 |
g_autofree char *checksum = NULL;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* FIXME: Add support for collection–refs. */
|
|
rpm-build |
0fba15 |
context = g_option_context_new ("REF COMMIT");
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error))
|
|
rpm-build |
0fba15 |
goto out;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!ostree_ensure_repo_writable (repo, error))
|
|
rpm-build |
0fba15 |
goto out;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (argc <= 2)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
ot_util_usage_error (context, "A REF and COMMIT argument is required", error);
|
|
rpm-build |
0fba15 |
goto out;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
ref = argv[1];
|
|
rpm-build |
0fba15 |
target = argv[2];
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!ostree_repo_list_refs (repo, NULL, &known_refs, cancellable, error))
|
|
rpm-build |
0fba15 |
goto out;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!g_hash_table_contains (known_refs, ref))
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_set_error (error, G_IO_ERROR, G_IO_ERROR, "Invalid ref '%s'", ref);
|
|
rpm-build |
0fba15 |
goto out;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!ostree_repo_resolve_rev (repo, target, FALSE, &checksum, error))
|
|
rpm-build |
0fba15 |
goto out;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error))
|
|
rpm-build |
0fba15 |
goto out;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
ostree_repo_transaction_set_ref (repo, NULL, ref, checksum);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!ostree_repo_commit_transaction (repo, NULL, cancellable, error))
|
|
rpm-build |
0fba15 |
goto out;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
ret = TRUE;
|
|
rpm-build |
0fba15 |
out:
|
|
rpm-build |
0fba15 |
if (repo)
|
|
rpm-build |
0fba15 |
ostree_repo_abort_transaction (repo, cancellable, NULL);
|
|
rpm-build |
0fba15 |
return ret;
|
|
rpm-build |
0fba15 |
}
|