mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
tmpfiles: clean what an x entry keeps by the age of the entry
An x or X entry can have an age of its own in tmpfiles.d(5). What it
keeps from the cleaning of the directory above is then cleaned by that
age instead:
d /tmp 1777 root root 10d
x /tmp/build - - - 30d
tmpfiles does not read the age, so /tmp/build is never cleaned.
Clean the paths of such an entry by its age, with the entry itself
left out of what is kept.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
4 files changed
+33
-8
No files matched your search
+17
-6
@@ -596,6 +596,7 @@ struct keep {
|
||||
static struct keep *keeps;
|
||||
static int num_keeps;
|
||||
static int collect; /* Pass that only gathers the above */
|
||||
static const char *keep_own; /* Entry that cleans what it keeps, by its own age */
|
||||
|
||||
static void keep_add(const char *pattern, int self)
|
||||
{
|
||||
@@ -623,6 +624,8 @@ static int kept(const char *path)
|
||||
for (int i = 0; i < num_keeps; i++) {
|
||||
struct keep *k = &keeps[i];
|
||||
|
||||
if (keep_own && !strcmp(k->pattern, keep_own))
|
||||
continue;
|
||||
if (!fnmatch(k->pattern, path, FNM_PATHNAME | (k->self ? 0 : FNM_LEADING_DIR)))
|
||||
return 1;
|
||||
}
|
||||
@@ -1612,7 +1615,7 @@ static void tmpfiles(char *line)
|
||||
|
||||
if (remove_flag && strchr("DrR", type[0]))
|
||||
printf("remove %s %s\n", type, path);
|
||||
if (clean_flag && strchr("CdDe", type[0]) && !parse_age(age, &clean_age))
|
||||
if (clean_flag && strchr("CdDexX", type[0]) && !parse_age(age, &clean_age))
|
||||
printf("clean %s %s, older than %s\n", type, path, age);
|
||||
if (create_flag && !strchr("rRxX", type[0]))
|
||||
printf("create %s %s%s%s\n", type, path, arg && !b64 ? " " : "", arg && !b64 ? arg : "");
|
||||
@@ -1670,16 +1673,24 @@ static void tmpfiles(char *line)
|
||||
}
|
||||
|
||||
/* age-based cleanup logic */
|
||||
if (clean_flag && strchr("CdDe", type[0]) && !parse_age(age, &clean_age)) {
|
||||
if (clean_flag && strchr("CdDexX", type[0]) && !parse_age(age, &clean_age)) {
|
||||
clean_now = time(NULL);
|
||||
|
||||
/* Only e takes a glob, and nothing is older than the epoch */
|
||||
if (clean_age.sec > clean_now)
|
||||
/* Only e, x, and X take a glob, and nothing is older than the epoch */
|
||||
if (clean_age.sec > clean_now) {
|
||||
;
|
||||
else if (type[0] == 'e')
|
||||
} else if (type[0] == 'x' || type[0] == 'X') {
|
||||
/* As keep_add() has it */
|
||||
for (size_t len = strlen(path); len > 1 && path[len - 1] == '/'; len--)
|
||||
path[len - 1] = 0;
|
||||
keep_own = path;
|
||||
glob_do(path, clean_dir);
|
||||
else
|
||||
keep_own = NULL;
|
||||
} else if (type[0] == 'e') {
|
||||
glob_do(path, clean_dir);
|
||||
} else {
|
||||
clean_dir(path);
|
||||
}
|
||||
}
|
||||
|
||||
// file & directory creation logic
|
||||
|
||||
Reference in new issue
Block a user