mirror of
https://github.com/ostreedev/ostree.git
synced 2025-01-03 05:18:24 +03:00
Merge 42847b097a
into 8aaea0c65d
This commit is contained in:
commit
c8152b14cc
@ -76,6 +76,7 @@ ostree_SOURCES += \
|
|||||||
src/ostree/ot-admin-builtin-set-default.c \
|
src/ostree/ot-admin-builtin-set-default.c \
|
||||||
src/ostree/ot-admin-builtin-instutil.c \
|
src/ostree/ot-admin-builtin-instutil.c \
|
||||||
src/ostree/ot-admin-builtin-kargs.c \
|
src/ostree/ot-admin-builtin-kargs.c \
|
||||||
|
src/ostree/ot-admin-builtin-metadata.c \
|
||||||
src/ostree/ot-admin-builtin-cleanup.c \
|
src/ostree/ot-admin-builtin-cleanup.c \
|
||||||
src/ostree/ot-admin-builtin-os-init.c \
|
src/ostree/ot-admin-builtin-os-init.c \
|
||||||
src/ostree/ot-admin-builtin-set-origin.c \
|
src/ostree/ot-admin-builtin-set-origin.c \
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "ostree-deployment-private.h"
|
#include "ostree-deployment-private.h"
|
||||||
|
#include "ostree-sysroot-private.h"
|
||||||
#include "ostree.h"
|
#include "ostree.h"
|
||||||
#include "otutil.h"
|
#include "otutil.h"
|
||||||
|
|
||||||
@ -476,3 +477,62 @@ ostree_deployment_is_finalization_locked (OstreeDeployment *self)
|
|||||||
{
|
{
|
||||||
return self->finalization_locked;
|
return self->finalization_locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ostree_deployment_set_ext_metadata:
|
||||||
|
* @self: Deployment
|
||||||
|
* @metadata_key: extended attribute(metadata) name/key to add.
|
||||||
|
* @metadata_value: extended attribute(metadata) value to add.
|
||||||
|
* @error: a #GError
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
ostree_deployment_set_ext_metadata (OstreeDeployment *self, const char *metadata_key,
|
||||||
|
const char *metadata_value, GError **error)
|
||||||
|
{
|
||||||
|
g_autofree char *backing_relpath = _ostree_sysroot_get_deployment_backing_relpath (self);
|
||||||
|
if (setxattr (backing_relpath, metadata_key, metadata_value, strlen (metadata_value), 0) < 0)
|
||||||
|
{
|
||||||
|
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
|
||||||
|
"Failed to set deployment metadata %s on %s: %s", metadata_key, backing_relpath,
|
||||||
|
g_strerror (errno));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ostree_deployment_get_ext_metadata:
|
||||||
|
* @self: Deployment
|
||||||
|
* @metadata_key: (nullable): key of extended attribute
|
||||||
|
* @error: a #GError
|
||||||
|
* Returns: The value of a extended attribute(metadata) checksum given the key.
|
||||||
|
*/
|
||||||
|
const char *
|
||||||
|
ostree_deployment_get_ext_metadata (OstreeDeployment *self, const char *metadata_key,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
g_autofree char *backing_relpath = _ostree_sysroot_get_deployment_backing_relpath (self);
|
||||||
|
g_autofree char *metadata_value = NULL;
|
||||||
|
g_autofree int len = getxattr (backing_relpath, metadata_key, NULL, 0);
|
||||||
|
if (len < 0)
|
||||||
|
{
|
||||||
|
if (errno == ENODATA)
|
||||||
|
return NULL;
|
||||||
|
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
|
||||||
|
"Failed to get deployment metadata %s on %s: %s", metadata_key, backing_relpath,
|
||||||
|
g_strerror (errno));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
metadata_value = g_malloc (len + 1);
|
||||||
|
len = getxattr (backing_relpath, metadata_key, metadata_value, len);
|
||||||
|
if (len < 0)
|
||||||
|
{
|
||||||
|
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
|
||||||
|
"Failed to get deployment metadata %s on %s: %s", metadata_key, backing_relpath,
|
||||||
|
g_strerror (errno));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
metadata_value[len] = '\0';
|
||||||
|
return metadata_value;
|
||||||
|
}
|
||||||
|
@ -107,4 +107,12 @@ const char *ostree_deployment_unlocked_state_to_string (OstreeDeploymentUnlocked
|
|||||||
_OSTREE_PUBLIC
|
_OSTREE_PUBLIC
|
||||||
OstreeDeploymentUnlockedState ostree_deployment_get_unlocked (OstreeDeployment *self);
|
OstreeDeploymentUnlockedState ostree_deployment_get_unlocked (OstreeDeployment *self);
|
||||||
|
|
||||||
|
_OSTREE_PUBLIC
|
||||||
|
gboolean ostree_deployment_set_ext_metadata (OstreeDeployment *self, const char *metadata_key,
|
||||||
|
const char *metadata_value, GError **error);
|
||||||
|
|
||||||
|
_OSTREE_PUBLIC
|
||||||
|
const char *ostree_deployment_get_ext_metadata (OstreeDeployment *self, const char *metadata_key,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
77
src/ostree/ot-admin-builtin-metadata.c
Normal file
77
src/ostree/ot-admin-builtin-metadata.c
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 Colin Walters <walters@verbum.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.0+
|
||||||
|
*
|
||||||
|
* This library 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "ot-admin-builtins.h"
|
||||||
|
#include "ot-admin-functions.h"
|
||||||
|
#include "otutil.h"
|
||||||
|
|
||||||
|
static char **opt_set;
|
||||||
|
static char **opt_get;
|
||||||
|
|
||||||
|
static GOptionEntry options[]
|
||||||
|
= { { "set", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_set,
|
||||||
|
"Set deployment metadata, like DATE=030424; this overrides any metadata with the "
|
||||||
|
"same name",
|
||||||
|
"KEY=VALUE" },
|
||||||
|
{ "get", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_get,
|
||||||
|
"Get the value of a deployment metadata.", "KEY" },
|
||||||
|
{ NULL } };
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
ot_admin_builtin_metadata (int argc, char **argv, OstreeCommandInvocation *invocation,
|
||||||
|
GCancellable *cancellable, GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
g_autoptr (GPtrArray) deployments = NULL;
|
||||||
|
OstreeDeployment *first_deployment = NULL;
|
||||||
|
g_autoptr (GOptionContext) context = NULL;
|
||||||
|
g_autoptr (OstreeSysroot) sysroot = NULL;
|
||||||
|
|
||||||
|
if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
|
||||||
|
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot,
|
||||||
|
cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (deployments->len == 0)
|
||||||
|
{
|
||||||
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unable to find a deployment in sysroot");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
first_deployment = deployments->pdata[0];
|
||||||
|
|
||||||
|
if (opt_set)
|
||||||
|
{
|
||||||
|
char *key = strtok (*opt_set, "=");
|
||||||
|
char *value = strtok (NULL, "=");
|
||||||
|
// ^^ This needs error checking and probably is wrong... but builds!
|
||||||
|
ostree_deployment_set_ext_metadata (first_deployment, key, value, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opt_get)
|
||||||
|
{
|
||||||
|
ostree_deployment_get_ext_metadata (first_deployment, *opt_get, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
@ -51,6 +51,7 @@ BUILTINPROTO (kargs);
|
|||||||
BUILTINPROTO (post_copy);
|
BUILTINPROTO (post_copy);
|
||||||
BUILTINPROTO (lock_finalization);
|
BUILTINPROTO (lock_finalization);
|
||||||
BUILTINPROTO (state_overlay);
|
BUILTINPROTO (state_overlay);
|
||||||
|
BUILTINPROTO (metadata);
|
||||||
|
|
||||||
#undef BUILTINPROTO
|
#undef BUILTINPROTO
|
||||||
|
|
||||||
|
@ -70,6 +70,8 @@ static OstreeCommand admin_subcommands[] = {
|
|||||||
{ "upgrade", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_upgrade,
|
{ "upgrade", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_upgrade,
|
||||||
"Construct new tree from current origin and deploy it, if it changed" },
|
"Construct new tree from current origin and deploy it, if it changed" },
|
||||||
{ "kargs", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_kargs, "Change kernel arguments" },
|
{ "kargs", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_kargs, "Change kernel arguments" },
|
||||||
|
{ "deployment-metadata", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_metadata,
|
||||||
|
"Set extended metadata for current the deployment" },
|
||||||
{ NULL, 0, NULL, NULL }
|
{ NULL, 0, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user