-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deployment: enable adding custom metadata #3212
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,4 +107,12 @@ const char *ostree_deployment_unlocked_state_to_string (OstreeDeploymentUnlocked | |
_OSTREE_PUBLIC | ||
OstreeDeploymentUnlockedState ostree_deployment_get_unlocked (OstreeDeployment *self); | ||
|
||
_OSTREE_PUBLIC | ||
gboolean ostree_deployment_set_ext_metadata (OstreeDeployment *self, const char *metadata_key, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New API needs to be added to |
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (C) 2015 Colin Walters <[email protected]> | ||
* | ||
* 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to handle errors here |
||
} | ||
|
||
ret = TRUE; | ||
out: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In brand new code we can avoid use of |
||
return ret; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the general case ostree wants to support using fd-relative paths, so we need to open a fd for the dir (relative to
self->sysroot_fd
), then usefgetxattr()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also
Definitely don't want to call
free()
on an integer. Also,getxattr
returns assize_t
, not anint
(they're different sizes).