From 9179d1b27aa8ac9c1ee731ffbc81672079019b23 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 8 May 2012 09:14:03 -0400 Subject: [PATCH] ostadmin: Make a /ostree/current symbolic link --- src/ostadmin/ot-admin-builtin-deploy.c | 40 ++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/ostadmin/ot-admin-builtin-deploy.c b/src/ostadmin/ot-admin-builtin-deploy.c index d935c2d6..43a4c44c 100644 --- a/src/ostadmin/ot-admin-builtin-deploy.c +++ b/src/ostadmin/ot-admin-builtin-deploy.c @@ -258,6 +258,38 @@ update_grub (const char *release, return ret; } +static gboolean +update_current (const char *last_deploy_target, + GCancellable *cancellable, + GError **error) +{ + gboolean ret = FALSE; + ot_lfree char *tmp_symlink = NULL; + ot_lfree char *current_name = NULL; + + tmp_symlink = g_build_filename ("/ostree", "tmp-current", NULL); + (void) unlink (tmp_symlink); + + if (symlink (last_deploy_target, tmp_symlink) < 0) + { + ot_util_set_error_from_errno (error, errno); + goto out; + } + + current_name = g_build_filename ("/ostree", "current", NULL); + if (rename (tmp_symlink, current_name) < 0) + { + ot_util_set_error_from_errno (error, errno); + goto out; + } + + g_print ("/ostree/current set to %s\n", last_deploy_target); + + ret = TRUE; + out: + return ret; +} + gboolean ot_admin_builtin_deploy (int argc, char **argv, GError **error) { @@ -298,11 +330,12 @@ ot_admin_builtin_deploy (int argc, char **argv, GError **error) if (!opt_checkout_only) { + struct utsname utsname; const char *release; - + (void) uname (&utsname); - + if (strcmp (utsname.sysname, "Linux") != 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, @@ -319,6 +352,9 @@ ot_admin_builtin_deploy (int argc, char **argv, GError **error) goto out; } + if (!update_current (last_deploy_target, cancellable, error)) + goto out; + ret = TRUE; out: if (context)