From a00cf54f3e4696bf7f7fedfb67fa2409162717c3 Mon Sep 17 00:00:00 2001 From: HuijingHei Date: Thu, 7 Nov 2024 11:17:01 +0800 Subject: [PATCH] filetree: skip the error if removing unexisting files Fixes https://github.com/coreos/bootupd/issues/762 --- src/filetree.rs | 13 ++++++++++--- tests/e2e-update/e2e-update-in-vm.sh | 12 ++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/filetree.rs b/src/filetree.rs index 0916d46e..af890bfb 100644 --- a/src/filetree.rs +++ b/src/filetree.rs @@ -348,7 +348,7 @@ pub(crate) fn apply_diff( path_tmp = path.to_path_buf(); } destdir - .remove_file(path_tmp.as_std_path()) + .remove_file_optional(path_tmp.as_std_path()) .with_context(|| format!("removing {:?}", path_tmp))?; } } @@ -691,12 +691,19 @@ mod tests { assert_eq!(b_btime_foo_new, b_btime_foo); } { - a.remove_file(testfile)?; + b.remove_file(testfile)?; + let ta = FileTree::new_from_dir(&a)?; + let diff = ta.relative_diff_to(&b)?; + assert_eq!(diff.removals.len(), 1); + apply_diff(&a, &b, &diff, None).context("test removed files with relative_diff")?; + assert_eq!(b.exists(testfile)?, false); + } + { a.remove_file(bar)?; let diff = run_diff(&b, &a)?; assert_eq!(diff.count(), 2); apply_diff(&a, &b, &diff, None).context("test removed files")?; - assert_eq!(b.exists(testfile)?, false); + assert_eq!(b.exists(testfile)?, true); assert_eq!(b.exists(bar)?, false); let diff = run_diff(&b, &a)?; assert_eq!(diff.count(), 0); diff --git a/tests/e2e-update/e2e-update-in-vm.sh b/tests/e2e-update/e2e-update-in-vm.sh index a3577533..b6bf6e53 100755 --- a/tests/e2e-update/e2e-update-in-vm.sh +++ b/tests/e2e-update/e2e-update-in-vm.sh @@ -89,8 +89,20 @@ rm -f /boot/bootupd-state.json bootupctl adopt-and-update | tee out.txt assert_file_has_content out.txt "Adopted and updated: BIOS: .*" assert_file_has_content out.txt "Adopted and updated: EFI: .*" +bootupctl validate ok adopt-and-update +# Verify the adoption does not fail when install files if they are missing on the disk. +# see https://github.com/coreos/bootupd/issues/762 +rm -f /boot/bootupd-state.json +[ -f "${tmpefimount}/EFI/fedora/test-bootupd.efi" ] && rm -f ${tmpefimount}/EFI/fedora/test-bootupd.efi +bootupctl adopt-and-update | tee out.txt +assert_file_has_content out.txt "Adopted and updated: BIOS: .*" +assert_file_has_content out.txt "Adopted and updated: EFI: .*" +if bootupctl validate 2>err.txt; then + fatal "unexpectedly passed validation" +fi + tap_finish touch /run/testtmp/success sync