Skip to content

Commit 1101839

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 3632dff commit 1101839

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
@@ -336,34 +336,34 @@ pub(crate) async fn delete_composefs_deployment(deployment_id: &str, delete: boo
336336

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

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

349-
let state_dir = Path::new(STATE_DIR_RELATIVE).join(deployment_id);
341+
// Delete the image
342+
let img_path = Path::new("composefs").join("images").join(deployment_id);
350343
sysroot
351-
.remove_dir_all(&state_dir)
352-
.with_context(|| format!("Removing dir {state_dir:?}"))?;
344+
.remove_file(&img_path)
345+
.context("Deleting EROFS image")?;
353346

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

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

368368
Ok(())
369369
}

0 commit comments

Comments
 (0)