From 56de6317212c15fed003e4ac2b52f5c4eb6d498c Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 12 Apr 2018 12:43:39 -0400 Subject: [PATCH] deploy: Clean up bootserial assignment function The reason we were returning a hashtable is a bit lost to history, there's no reason to do so now anyways. Also port to declare-and-initialize style and add more comments. Closes: #1538 Approved by: jlebon --- src/libostree/ostree-sysroot-deploy.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index b593ce38..d3540c8d 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -1874,26 +1874,26 @@ swap_bootloader (OstreeSysroot *sysroot, return TRUE; } -static GHashTable * +/* Deployments may share boot checksums; the bootserial indexes them + * per-bootchecksum. It's used by the symbolic links after the bootloader. + */ +static void assign_bootserials (GPtrArray *deployments) { - guint i; - GHashTable *ret = + g_autoptr(GHashTable) serials = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); - for (i = 0; i < deployments->len; i++) + for (guint i = 0; i < deployments->len; i++) { OstreeDeployment *deployment = deployments->pdata[i]; const char *bootcsum = ostree_deployment_get_bootcsum (deployment); - guint count; - - count = GPOINTER_TO_UINT (g_hash_table_lookup (ret, bootcsum)); - g_hash_table_replace (ret, (char*) bootcsum, + /* Note that not-found maps to NULL which converts to zero */ + guint count = GPOINTER_TO_UINT (g_hash_table_lookup (serials, bootcsum)); + g_hash_table_replace (serials, (char*) bootcsum, GUINT_TO_POINTER (count + 1)); ostree_deployment_set_bootserial (deployment, count); } - return ret; } /* OSTree implements a special optimization where we want to avoid touching @@ -2146,7 +2146,7 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, /* Assign a bootserial to each new deployment. */ - g_hash_table_unref (assign_bootserials (new_deployments)); + assign_bootserials (new_deployments); /* Determine whether or not we need to touch the bootloader * configuration. If we have an equal number of deployments with