ostree admin: Add a --print-current-dir option
Add an option --print-current-dir that prints the current deployment directory to stdout and exits. https://bugzilla.gnome.org/show_bug.cgi?id=731051
This commit is contained in:
parent
262cba09c0
commit
d64d003af0
|
|
@ -97,6 +97,13 @@ Boston, MA 02111-1307, USA.
|
|||
<term><option>--sysroot</option>="PATH"</term>
|
||||
<listitem><para>Creates a new OSTree sysroot at PATH</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--print-current-dir</option></term>
|
||||
<listitem><para>
|
||||
Prints the full path to the deployment directory for the currently active deployment in the specified sysroot to standard out. This is incompatible with specifying a subcommand.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ ostree_builtin_admin (int argc, char **argv, OstreeRepo *repo, GCancellable *can
|
|||
gs_unref_object GFile *sysroot_path = NULL;
|
||||
gs_unref_object OstreeSysroot *sysroot = NULL;
|
||||
gboolean want_help = FALSE;
|
||||
gboolean want_current_dir = FALSE;
|
||||
int in, out, i;
|
||||
gboolean skip;
|
||||
|
||||
|
|
@ -93,6 +94,10 @@ ostree_builtin_admin (int argc, char **argv, OstreeRepo *repo, GCancellable *can
|
|||
{
|
||||
want_help = TRUE;
|
||||
}
|
||||
else if (g_str_equal (argv[in], "--print-current-dir"))
|
||||
{
|
||||
want_current_dir = TRUE;
|
||||
}
|
||||
else if (g_str_equal (argv[in], "--sysroot") && in + 1 < argc)
|
||||
{
|
||||
opt_sysroot = argv[in + 1];
|
||||
|
|
@ -145,12 +150,12 @@ ostree_builtin_admin (int argc, char **argv, OstreeRepo *repo, GCancellable *can
|
|||
|
||||
argc = out;
|
||||
|
||||
if (subcommand_name == NULL)
|
||||
if (subcommand_name == NULL && (want_help || !want_current_dir))
|
||||
{
|
||||
void (*print_func) (const gchar *format, ...) = want_help ? g_print : g_printerr;
|
||||
|
||||
subcommand = admin_subcommands;
|
||||
print_func ("usage: ostree admin --sysroot=PATH COMMAND [options]\n");
|
||||
print_func ("usage: ostree admin [--sysroot=PATH] [--print-current-dir|COMMAND] [options]\n");
|
||||
print_func ("Builtin commands:\n");
|
||||
while (subcommand->name)
|
||||
{
|
||||
|
|
@ -166,6 +171,35 @@ ostree_builtin_admin (int argc, char **argv, OstreeRepo *repo, GCancellable *can
|
|||
goto out;
|
||||
}
|
||||
|
||||
sysroot_path = g_file_new_for_path (opt_sysroot);
|
||||
sysroot = ostree_sysroot_new (sysroot_path);
|
||||
|
||||
if (want_current_dir)
|
||||
{
|
||||
gs_unref_ptrarray GPtrArray *deployments = NULL;
|
||||
OstreeDeployment *first_deployment;
|
||||
gs_unref_object GFile *deployment_file = NULL;
|
||||
gs_free char *deployment_path = NULL;
|
||||
|
||||
if (!ostree_sysroot_load (sysroot, cancellable, error))
|
||||
goto out;
|
||||
|
||||
deployments = ostree_sysroot_get_deployments (sysroot);
|
||||
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];
|
||||
deployment_file = ostree_sysroot_get_deployment_directory (sysroot, first_deployment);
|
||||
deployment_path = g_file_get_path (deployment_file);
|
||||
|
||||
g_print ("%s\n", deployment_path);
|
||||
ret = TRUE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
subcommand = admin_subcommands;
|
||||
while (subcommand->name)
|
||||
{
|
||||
|
|
@ -183,8 +217,6 @@ ostree_builtin_admin (int argc, char **argv, OstreeRepo *repo, GCancellable *can
|
|||
|
||||
g_set_prgname (g_strdup_printf ("ostree admin %s", subcommand_name));
|
||||
|
||||
sysroot_path = g_file_new_for_path (opt_sysroot);
|
||||
sysroot = ostree_sysroot_new (sysroot_path);
|
||||
if (!subcommand->fn (argc, argv, sysroot, cancellable, error))
|
||||
goto out;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue