From 27f20f6e2630cb02bde420b0ec43e659d6ddfa53 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Wed, 3 May 2023 12:51:13 +0200 Subject: [PATCH] build_library/build_image_util.sh: Remove temporary /etc backup The temporary /etc backup created during emerging packages should only contain empty files that will make sure that the symlinks pointing to files within the /etc backup won't dangle at any time. --- build_library/build_image_util.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index bc0b6cc756..dad7554f78 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -836,9 +836,18 @@ EOF sudo setfiles -Dv -r "${root_fs_dir}" "${root_fs_dir}"/etc/selinux/mcs/contexts/files/file_contexts "${root_fs_dir}"/etc fi - # Backup the /etc contents to /usr/share/flatcar/etc to serve as source - # for creating missing files + # Backup the /etc contents to /usr/share/flatcar/etc to serve as + # source for creating missing files. Make sure that the preexisting + # /usr/share/flatcar/etc does not have any meaningful (non-empty) + # files, so we remove nothing important. There shouldn't be any + # symlinks either. Add "! -type d" to exclude directories as "stat" + # usually returns a size of a directory being 4096 or so. + if [[ $(sudo find "${root_fs_dir}/usr/share/flatcar/etc" -size +0 ! -type d 2>/dev/null | wc -l) -gt 0 ]]; then + die "Unexpected non-empty files in ${root_fs_dir}/usr/share/flatcar/etc" + fi + sudo rm -rf "${root_fs_dir}/usr/share/flatcar/etc" sudo cp -a "${root_fs_dir}/etc" "${root_fs_dir}/usr/share/flatcar/etc" + # Remove the rootfs state as it should be recreated through the # tmpfiles and may not be present on updating machines. This # makes sure our tests cover the case of missing files in the