From 75a19cd8181f879f1072e3e553f01737e35fbb28 Mon Sep 17 00:00:00 2001 From: nikstur Date: Mon, 20 Feb 2023 00:41:53 +0100 Subject: [PATCH] tool: correctly sort generation links To correctly overwrite existing initrd with newer secrets (from newer generations), the links need to be sorted from oldest generation to newest. --- rust/tool/src/install.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rust/tool/src/install.rs b/rust/tool/src/install.rs index cc7fffb..4be05fe 100644 --- a/rust/tool/src/install.rs +++ b/rust/tool/src/install.rs @@ -61,16 +61,22 @@ impl Installer { .map(GenerationLink::from_path) .collect::>>()?; + // Sort the links by version. The links need to always be sorted to ensure the secrets of + // the latest generation are appended to the initrd when multiple generations point to the + // same initrd. + links.sort_by_key(|l| l.version); + // A configuration limit of 0 means there is no limit. if self.configuration_limit > 0 { - // Sort the links by version. - links.sort_by_key(|l| l.version); - - // Only install the number of generations configured. + // Only install the number of generations configured. Reverse the list to only take the + // latest generations and then, after taking them, reverse the list again so that the + // generations are installed from oldest to newest, i.e. from smallest to largest + // generation version. links = links .into_iter() .rev() .take(self.configuration_limit) + .rev() .collect() }; self.install_generations_from_links(&links)?;