core: copy os-release with COPY_TRUNCATE

Otherwise if the os-release file shrinks between updates, there
will be a merge of the two.
Also remove redundant ENOENT check.

Follow-up for 3f37a82545
This commit is contained in:
Luca Boccassi 2023-08-11 14:42:02 +01:00
parent 9a441937e1
commit bf85c2395e
2 changed files with 4 additions and 4 deletions

View file

@ -1406,10 +1406,10 @@ static int setup_os_release(RuntimeScope scope) {
}
r = mkdir_parents_label(os_release_dst, 0755);
if (r < 0 && r != -EEXIST)
if (r < 0)
return log_debug_errno(r, "Failed to create parent directory of %s, ignoring: %m", os_release_dst);
r = copy_file(os_release_src, os_release_dst, /* open_flags= */ 0, 0644, COPY_MAC_CREATE);
r = copy_file(os_release_src, os_release_dst, /* open_flags= */ 0, 0644, COPY_MAC_CREATE|COPY_TRUNCATE);
if (r < 0)
return log_debug_errno(r, "Failed to create %s, ignoring: %m", os_release_dst);

View file

@ -92,9 +92,9 @@ elif [ -f /run/testsuite82.touch ]; then
echo miep >/tmp/nextroot-lower/lower
# Copy os-release away, so that we can manipulate it and check that it is updated in the propagate
# directory across soft reboots.
# directory across soft reboots. Try to cover corner cases by truncating it.
mkdir -p /tmp/nextroot-lower/usr/lib
cp /etc/os-release /tmp/nextroot-lower/usr/lib/os-release
grep ID /etc/os-release >/tmp/nextroot-lower/usr/lib/os-release
echo MARKER=1 >>/tmp/nextroot-lower/usr/lib/os-release
cmp /etc/os-release /run/systemd/propagate/os-release
(! grep -q MARKER=1 /etc/os-release)