tmpfiles: inherit age-by for X entries
X entries inherit the cleanup age from the closest parent directory rule.
Inherit the age-by fields too, so parent rules such as m:1d keep their
full cleanup policy.
Reproducer:
mkdir -p /tmp/tmpfiles-ageby/parent/{child,other}
printf old >/tmp/tmpfiles-ageby/parent/child/file
printf old >/tmp/tmpfiles-ageby/parent/other/file
touch -d '3 days ago' /tmp/tmpfiles-ageby/parent/{child,other}/file
systemd-tmpfiles --clean - <<'EOT'
d /tmp/tmpfiles-ageby/parent - - - m:1d
X /tmp/tmpfiles-ageby/parent/child - - - -
EOT
Before:
child/file remained because X used the default age-by set.
other/file was removed by the parent m: rule.
Follow-up for 7f7a50dd15.
This commit is contained in:
@@ -4720,6 +4720,8 @@ static int read_config_file(
|
||||
if (candidate_item && candidate_item->age_set) {
|
||||
i->age = candidate_item->age;
|
||||
i->age_set = true;
|
||||
i->age_by_file = candidate_item->age_by_file;
|
||||
i->age_by_dir = candidate_item->age_by_dir;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -219,3 +219,19 @@ after="$(stat -c %Y /tmp/ageby-mtime)"
|
||||
test "$before" = "$after"
|
||||
test ! -e /tmp/ageby-mtime/old-child
|
||||
rmdir /tmp/ageby-mtime
|
||||
|
||||
# X entries inherit the parent cleanup age and its age-by fields.
|
||||
rm -rf /tmp/ageby-x-inherit
|
||||
mkdir -p /tmp/ageby-x-inherit/parent/child /tmp/ageby-x-inherit/parent/other
|
||||
printf old >/tmp/ageby-x-inherit/parent/child/file
|
||||
printf old >/tmp/ageby-x-inherit/parent/other/file
|
||||
touch --date "3 days ago" /tmp/ageby-x-inherit/parent/child/file /tmp/ageby-x-inherit/parent/other/file
|
||||
|
||||
systemd-tmpfiles --clean - <<-EOF
|
||||
d /tmp/ageby-x-inherit/parent - - - m:1d
|
||||
X /tmp/ageby-x-inherit/parent/child - - - -
|
||||
EOF
|
||||
|
||||
test ! -e /tmp/ageby-x-inherit/parent/child/file
|
||||
test ! -e /tmp/ageby-x-inherit/parent/other/file
|
||||
rm -rf /tmp/ageby-x-inherit
|
||||
|
||||
Reference in New Issue
Block a user