Skip to content

Commit

Permalink
filetree: skip the error if removing unexisting files
Browse files Browse the repository at this point in the history
  • Loading branch information
HuijingHei committed Nov 12, 2024
1 parent 493c95f commit 804bf20
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/filetree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?;
}
}
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions tests/e2e-update/e2e-update-in-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 804bf20

Please sign in to comment.