]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tmpfiles: inherit age-by for X entries 43031/head
authordongshengyuan <545258830@qq.com>
Wed, 15 Jul 2026 05:35:57 +0000 (13:35 +0800)
committerdongshengyuan <545258830@qq.com>
Fri, 24 Jul 2026 05:44:37 +0000 (13:44 +0800)
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 7f7a50dd157b3bfb4282c3cc3a56671121eabe24.

src/tmpfiles/tmpfiles.c
test/units/TEST-22-TMPFILES.12.sh

index 72781a49b72130686dcae9fee8eda76ac60ed708..464384b22bd9ffaeb68cf1472693505c763ca660 100644 (file)
@@ -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;
                         }
                 }
 
index 1aa4faa0d380511fef242c378263b658a2ce4e98..b2288bcf016208e6d525b1992fc4e649dbddff5e 100755 (executable)
@@ -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