Skip to content

Commit 883110d

Browse files
composefs-backend: Update the order of deletion
Delete the boot entries first, the image second and everything else afterwards. If we fail to delete the boot entry, then there's no point in deleting the image as the boot entry will still show, but there will be no image. We delete the objects at the end, as when we later perform a gc operation and don't find the image that references these objects, we can remove them then. The state directory shouldn't have any effect on boot if the image associated to it doesn't exist. If the staged file /run/composefs/staged-deployment does exist, but we have already deleted the staged image, the finalize service would fail but that wouldn't break anything Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent 11948a9 commit 883110d

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

crates/lib/src/bootc_composefs/delete.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -337,34 +337,34 @@ pub(crate) async fn delete_composefs_deployment(deployment_id: &str, delete: boo
337337

338338
tracing::info!("Deleting {kind}deployment '{deployment_id}'");
339339

340-
for sha in diff {
341-
let object_path = Path::new("composefs")
342-
.join("objects")
343-
.join(sha.to_object_pathname());
344-
345-
sysroot
346-
.remove_file(&object_path)
347-
.with_context(|| format!("Removing {object_path:?}"))?;
348-
}
340+
delete_depl_boot_entries(&depl_to_del, deleting_staged)?;
349341

350-
let state_dir = Path::new(STATE_DIR_RELATIVE).join(deployment_id);
342+
// Delete the image
343+
let img_path = Path::new("composefs").join("images").join(deployment_id);
351344
sysroot
352-
.remove_dir_all(&state_dir)
353-
.with_context(|| format!("Removing dir {state_dir:?}"))?;
345+
.remove_file(&img_path)
346+
.context("Deleting EROFS image")?;
354347

355348
if deleting_staged {
356349
let file = Path::new(COMPOSEFS_TRANSIENT_STATE_DIR).join(COMPOSEFS_STAGED_DEPLOYMENT_FNAME);
357350
tracing::debug!("Deleting staged file {file:?}");
358351
std::fs::remove_file(file).context("Removing staged file")?;
359352
}
360353

361-
delete_depl_boot_entries(&depl_to_del, deleting_staged)?;
362-
363-
// Delete the image
364-
let img_path = Path::new("composefs").join("images").join(deployment_id);
354+
let state_dir = Path::new(STATE_DIR_RELATIVE).join(deployment_id);
365355
sysroot
366-
.remove_file(&img_path)
367-
.context("Deleting EROFS image")?;
356+
.remove_dir_all(&state_dir)
357+
.with_context(|| format!("Removing dir {state_dir:?}"))?;
358+
359+
for sha in diff {
360+
let object_path = Path::new("composefs")
361+
.join("objects")
362+
.join(sha.to_object_pathname());
363+
364+
sysroot
365+
.remove_file(&object_path)
366+
.with_context(|| format!("Removing {object_path:?}"))?;
367+
}
368368

369369
Ok(())
370370
}

0 commit comments

Comments
 (0)