[ostree] sysroot: Sort returned boot loader configs
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] sysroot: Sort returned boot loader configs
- Date: Thu, 28 May 2015 23:51:39 +0000 (UTC)
commit 3300ee6259d191199f96b5f4e04ccfded3d11b86
Author: Colin Walters <walters verbum org>
Date: Tue May 26 18:46:47 2015 -0400
sysroot: Sort returned boot loader configs
I haven't done a full dig through the history, but it seems quite
possible right now we've been relying on inode enumeration
order for generating bootloader configuration.
Most of the time, newer inodes (i.e. later written files) will win.
But that's obviously not reliable.
Fix this by sorting the returned configuration internally.
src/libostree/ostree-sysroot.c | 47 ++++++++++++++++++++++++++++-----------
1 files changed, 34 insertions(+), 13 deletions(-)
---
diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c
index ebcb632..f12ebc5 100644
--- a/src/libostree/ostree-sysroot.c
+++ b/src/libostree/ostree-sysroot.c
@@ -361,6 +361,35 @@ _ostree_sysroot_read_current_subbootversion (OstreeSysroot *self,
return ret;
}
+static gint
+compare_boot_loader_configs (OstreeBootconfigParser *a,
+ OstreeBootconfigParser *b)
+{
+ const char *a_version = ostree_bootconfig_parser_get (a, "version");
+ const char *b_version = ostree_bootconfig_parser_get (b, "version");
+
+ if (a_version && b_version)
+ {
+ int r = strverscmp (a_version, b_version);
+ /* Reverse */
+ return -r;
+ }
+ else if (a_version)
+ return -1;
+ else
+ return 1;
+}
+
+static int
+compare_loader_configs_for_sorting (gconstpointer a_pp,
+ gconstpointer b_pp)
+{
+ OstreeBootconfigParser *a = *((OstreeBootconfigParser**)a_pp);
+ OstreeBootconfigParser *b = *((OstreeBootconfigParser**)b_pp);
+
+ return compare_boot_loader_configs (a, b);
+}
+
gboolean
_ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self,
int bootversion,
@@ -427,6 +456,9 @@ _ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self,
}
}
+ /* Callers expect us to give them a sorted array */
+ g_ptr_array_sort (ret_loader_configs, compare_loader_configs_for_sorting);
+
done:
gs_transfer_out_value (out_loader_configs, &ret_loader_configs);
ret = TRUE;
@@ -706,19 +738,8 @@ compare_deployments_by_boot_loader_version_reversed (gconstpointer a_pp,
OstreeDeployment *b = *((OstreeDeployment**)b_pp);
OstreeBootconfigParser *a_bootconfig = ostree_deployment_get_bootconfig (a);
OstreeBootconfigParser *b_bootconfig = ostree_deployment_get_bootconfig (b);
- const char *a_version = ostree_bootconfig_parser_get (a_bootconfig, "version");
- const char *b_version = ostree_bootconfig_parser_get (b_bootconfig, "version");
-
- if (a_version && b_version)
- {
- int r = strverscmp (a_version, b_version);
- /* Reverse */
- return -r;
- }
- else if (a_version)
- return -1;
- else
- return 1;
+
+ return compare_boot_loader_configs (a_bootconfig, b_bootconfig);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]