mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
tmpfiles: clean what an e entry with a glob matches
An e entry takes a glob, but cleaning looked for a directory with
the pattern as its name:
e /var/cache/* - - - 10d
tmpfiles --clean t.conf
This cleaned nothing.
Expand the glob and clean each directory it matches. Also use the
age of a C entry, tmpfiles.d(5) has it clean what it copied.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
3 files changed
+16
-6
No files matched your search
@@ -288,6 +288,9 @@ All relevant changes are documented in this file.
|
|||||||
`C`, `z`, and `Z` entries
|
`C`, `z`, and `Z` entries
|
||||||
- Fix tmpfiles `b` and `c` entries for a device with major or minor 0,
|
- Fix tmpfiles `b` and `c` entries for a device with major or minor 0,
|
||||||
like `5:0` for `/dev/tty`, they were skipped as invalid
|
like `5:0` for `/dev/tty`, they were skipped as invalid
|
||||||
|
- Fix `tmpfiles --clean` for an `e` entry with a glob in the path, like
|
||||||
|
`e /var/cache/* - - - 10d`, nothing was cleaned. The age of a `C`
|
||||||
|
entry is now used as well
|
||||||
- Fix age `0` in a tmpfiles entry, it was read as no age. As in
|
- Fix age `0` in a tmpfiles entry, it was read as no age. As in
|
||||||
tmpfiles.d(5), `tmpfiles --clean` now empties the directory of such an
|
tmpfiles.d(5), `tmpfiles --clean` now empties the directory of such an
|
||||||
entry
|
entry
|
||||||
|
|||||||
+7
-3
@@ -1198,11 +1198,15 @@ static void tmpfiles(char *line)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* age-based cleanup logic */
|
/* age-based cleanup logic */
|
||||||
if (clean_flag && strchr("dDe", type[0]) && !parse_age(age, &clean_age)) {
|
if (clean_flag && strchr("CdDe", type[0]) && !parse_age(age, &clean_age)) {
|
||||||
clean_now = time(NULL);
|
clean_now = time(NULL);
|
||||||
|
|
||||||
/* Nothing is older than the epoch */
|
/* Only e takes a glob, and nothing is older than the epoch */
|
||||||
if (clean_age.sec <= clean_now)
|
if (clean_age.sec > clean_now)
|
||||||
|
;
|
||||||
|
else if (type[0] == 'e')
|
||||||
|
glob_do(path, clean_dir);
|
||||||
|
else
|
||||||
clean_dir(path);
|
clean_dir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,19 +66,22 @@ assert_left $DIR/zero ""
|
|||||||
assert_left $DIR/none "file "
|
assert_left $DIR/none "file "
|
||||||
|
|
||||||
sep
|
sep
|
||||||
say 'Ages with several units, and ms'
|
say 'Ages with several units, ms, and what a path matched by e holds'
|
||||||
run "mkdir -p $DIR/units $DIR/msec $DIR/long $DIR/level/sub $DIR/by-all $DIR/by-m"
|
run "mkdir -p $DIR/units $DIR/msec $DIR/long $DIR/glob-1 $DIR/glob-2 $DIR/level/sub $DIR/by-all $DIR/by-m"
|
||||||
run "touch $DIR/units/file $DIR/msec/file $DIR/long/file"
|
run "touch $DIR/units/file $DIR/msec/file $DIR/long/file $DIR/glob-1/file $DIR/glob-2/file"
|
||||||
run "touch $DIR/level/file $DIR/level/sub/file $DIR/by-all/file $DIR/by-m/file"
|
run "touch $DIR/level/file $DIR/level/sub/file $DIR/by-all/file $DIR/by-m/file"
|
||||||
sleep 2
|
sleep 2
|
||||||
clean <<CONF
|
clean <<CONF
|
||||||
d $DIR/units - - - 0m1s
|
d $DIR/units - - - 0m1s
|
||||||
d $DIR/msec - - - 1500ms
|
d $DIR/msec - - - 1500ms
|
||||||
d $DIR/long - - - 1h1s
|
d $DIR/long - - - 1h1s
|
||||||
|
e $DIR/glob-* - - - 1s
|
||||||
CONF
|
CONF
|
||||||
assert_left $DIR/units ""
|
assert_left $DIR/units ""
|
||||||
assert_left $DIR/msec ""
|
assert_left $DIR/msec ""
|
||||||
assert_left $DIR/long "file "
|
assert_left $DIR/long "file "
|
||||||
|
assert_left $DIR/glob-1 ""
|
||||||
|
assert_left $DIR/glob-2 ""
|
||||||
|
|
||||||
sep
|
sep
|
||||||
say 'With ~ what is right in the directory is kept'
|
say 'With ~ what is right in the directory is kept'
|
||||||
|
|||||||
Reference in new issue
Block a user