repart: Fix deny list logic

Until now, we always excluded the top level directories that were
covered by child partition mount points, regardless of the source
directory and the target directory of the copy files operation.
This means that even if we were populating a XBOOTLDR partition, if
there was an EFI partition in the image, we'd exclude /boot
unconditionally, leading to the XBOOTLDR partition to be empty.

Also, because of the same cause, if we were copying a nested source
directory (e.g. /abc/def) to the root directory in the root
partition, if /abc/def/usr existed and was populated with files and
directories, the root partition would have those files under /usr,
even if a /usr partition was defined.

To fix these issues, instead of unconditionally excluding the top
level partition mount points under <source>, let's make sure that
when we're copying files from any source directory to the root
directory of a root partition, that we exclude the partition mount
point directories under the source directory instead of the top
level ones.
This commit is contained in:
Daan De Meyer
2023-05-10 18:07:47 +02:00
parent 39a39f18f2
commit e57b7020d2
2 changed files with 148 additions and 91 deletions
+19
View File
@@ -855,11 +855,19 @@ test_exclude_files() {
runas testuser touch "$root/usr/qed"
runas testuser mkdir "$root/tmp"
runas testuser touch "$root/tmp/prs"
runas testuser mkdir "$root/proc"
runas testuser touch "$root/proc/prs"
runas testuser mkdir "$root/zzz"
runas testuser mkdir "$root/zzz/usr"
runas testuser touch "$root/zzz/usr/prs"
runas testuser mkdir "$root/zzz/proc"
runas testuser touch "$root/zzz/proc/prs"
runas testuser tee "$defs/00-root.conf" <<EOF
[Partition]
Type=root-${architecture}
CopyFiles=/
CopyFiles=/zzz:/
EOF
runas testuser tee "$defs/10-usr.conf" <<EOF
@@ -893,6 +901,10 @@ EOF
assert_rc 0 ls "$imgs/mnt/usr"
assert_rc 2 ls "$imgs/mnt/usr/def"
# Test that /zzz/usr/prs did not end up in the root partition under /usr but did end up in /zzz/usr/prs
assert_rc 2 ls "$imgs/mnt/usr/prs"
assert_rc 0 ls "$imgs/mnt/zzz/usr/prs"
# Test that /tmp/prs did not end up in the root partition but /tmp did.
assert_rc 0 ls "$imgs/mnt/tmp"
assert_rc 2 ls "$imgs/mnt/tmp/prs"
@@ -902,6 +914,13 @@ EOF
assert_rc 0 ls "$imgs/mnt/usr/def"
assert_rc 2 ls "$imgs/mnt/usr/qed"
# Test that /zzz/proc/prs did not end up in the root partition but /proc did.
assert_rc 0 ls "$imgs/mnt/proc"
assert_rc 2 ls "$imgs/mnt/proc/prs"
# Test that /zzz/usr/prs did not end up in the usr partition.
assert_rc 2 ls "$imgs/mnt/usr/prs"
umount -R "$imgs/mnt"
losetup -d "$loop"
}