Skip to content

Commit acf6559

Browse files
Johan-Liebert1cgwalters
authored andcommitted
composefs-backend: Deleting deployments
Add a command to delete a composefs native deployment Deleting a deployment would mean, deleting the EROFS image, the bootloader entries for that deployment and deleting any objects in the composefs repository that are only referenced by said deployment. Also refactor some functions and add error contexts in some places Signed-off-by: Pragyan Poudyal <[email protected]> composefs-backend: Deleting staged deployment Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent 37fa085 commit acf6559

File tree

7 files changed

+457
-10
lines changed

7 files changed

+457
-10
lines changed

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const SYSTEMD_LOADER_CONF_PATH: &str = "loader/loader.conf";
6464
/// directory specified by the BLS spec. We do this because we want systemd-boot to only look at
6565
/// our config files and not show the actual UKIs in the bootloader menu
6666
/// This is relative to the ESP
67-
const SYSTEMD_UKI_DIR: &str = "EFI/Linux/bootc";
67+
pub(crate) const SYSTEMD_UKI_DIR: &str = "EFI/Linux/bootc";
6868

6969
pub(crate) enum BootSetupType<'a> {
7070
/// For initial setup, i.e. install to-disk
@@ -211,9 +211,9 @@ fn compute_boot_digest(
211211
/// Given the SHA256 sum of current VMlinuz + Initrd combo, find boot entry with the same SHA256Sum
212212
///
213213
/// # Returns
214-
/// Returns the verity of the deployment that has a boot digest same as the one passed in
214+
/// Returns the verity of all deployments that have a boot digest same as the one passed in
215215
#[context("Checking boot entry duplicates")]
216-
fn find_vmlinuz_initrd_duplicates(digest: &str) -> Result<Option<String>> {
216+
pub(crate) fn find_vmlinuz_initrd_duplicates(digest: &str) -> Result<Option<Vec<String>>> {
217217
let deployments = Dir::open_ambient_dir(STATE_DIR_ABS, ambient_authority());
218218

219219
let deployments = match deployments {
@@ -223,7 +223,7 @@ fn find_vmlinuz_initrd_duplicates(digest: &str) -> Result<Option<String>> {
223223
Err(e) => anyhow::bail!(e),
224224
};
225225

226-
let mut symlink_to: Option<String> = None;
226+
let mut symlink_to: Option<Vec<String>> = None;
227227

228228
for depl in deployments.entries()? {
229229
let depl = depl?;
@@ -243,8 +243,10 @@ fn find_vmlinuz_initrd_duplicates(digest: &str) -> Result<Option<String>> {
243243
match ini.get::<String>(ORIGIN_KEY_BOOT, ORIGIN_KEY_BOOT_DIGEST) {
244244
Some(hash) => {
245245
if hash == digest {
246-
symlink_to = Some(depl_file_name.to_string());
247-
break;
246+
match symlink_to {
247+
Some(ref mut prev) => prev.push(depl_file_name.to_string()),
248+
None => symlink_to = Some(vec![depl_file_name.to_string()]),
249+
}
248250
}
249251
}
250252

@@ -479,6 +481,8 @@ pub(crate) fn setup_composefs_bls_boot(
479481

480482
match find_vmlinuz_initrd_duplicates(&boot_digest)? {
481483
Some(symlink_to) => {
484+
let symlink_to = &symlink_to[0];
485+
482486
match bls_config.cfg_type {
483487
BLSConfigType::NonEFI {
484488
ref mut linux,

0 commit comments

Comments
 (0)