mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
tmpfiles: age 0 cleans everything
An entry with the age 0 was read as having no age, so nothing in its
directory was ever cleaned:
d /var/spool/work - - - 0
tmpfiles --clean t.conf
In tmpfiles.d(5) age 0 means everything in the directory is removed
on each clean. parse_age() returned 0 for both.
It now returns -1 for no age and for one it cannot read, and with
age 0 the timestamps are not looked at.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
3 files changed
+23
-6
No files matched your search
@@ -263,6 +263,9 @@ All relevant changes are documented in this file.
|
|||||||
file or in the files after it. Such an entry is now skipped with a warning
|
file or in the files after it. Such an entry is now skipped with a warning
|
||||||
- Fix `tmpfiles --clean` cleaning other file systems mounted below the
|
- Fix `tmpfiles --clean` cleaning other file systems mounted below the
|
||||||
directory of an entry, it now stays on the file system of the directory
|
directory of an entry, it now stays on the file system of the directory
|
||||||
|
- 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
|
||||||
|
entry
|
||||||
- Fix a lost reload for a service paused mid-reload by a condition in
|
- Fix a lost reload for a service paused mid-reload by a condition in
|
||||||
flux. A second reload arriving meanwhile re-parsed the unchanged .conf
|
flux. A second reload arriving meanwhile re-parsed the unchanged .conf
|
||||||
and cleared the pending mark, so the service resumed without ever being
|
and cleared the pending mark, so the service resumed without ever being
|
||||||
|
|||||||
+9
-6
@@ -270,7 +270,7 @@ static void write_arg(FILE *fp, char *arg)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse age string and return age in seconds.
|
* Parse age string and return age in seconds.
|
||||||
* Returns 0 on invalid/empty age ("-" or NULL).
|
* Returns -1 on invalid/empty age ("-" or NULL).
|
||||||
* Examples: "10d" = 864000, "1w" = 604800, "2h" = 7200
|
* Examples: "10d" = 864000, "1w" = 604800, "2h" = 7200
|
||||||
*/
|
*/
|
||||||
static time_t parse_age(const char *age)
|
static time_t parse_age(const char *age)
|
||||||
@@ -278,13 +278,13 @@ static time_t parse_age(const char *age)
|
|||||||
time_t val;
|
time_t val;
|
||||||
char *end;
|
char *end;
|
||||||
|
|
||||||
if (!age || !strcmp(age, "-") || !strcmp(age, "0"))
|
if (!age || !strcmp(age, "-"))
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
val = strtoul(age, &end, 10);
|
val = strtoul(age, &end, 10);
|
||||||
if (errno || end == age)
|
if (errno || end == age)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
switch (*end) {
|
switch (*end) {
|
||||||
case 'w':
|
case 'w':
|
||||||
@@ -303,7 +303,7 @@ static time_t parse_age(const char *age)
|
|||||||
case '\0':
|
case '\0':
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return 0; /* unknown suffix */
|
return -1; /* unknown suffix */
|
||||||
}
|
}
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
@@ -414,7 +414,9 @@ static int do_clean(const char *fpath, const struct stat *sb, int tflag, struct
|
|||||||
* - Files: keep if ANY of atime, ctime, mtime is recent
|
* - Files: keep if ANY of atime, ctime, mtime is recent
|
||||||
* - Directories: keep if ANY of atime, mtime is recent (ctime
|
* - Directories: keep if ANY of atime, mtime is recent (ctime
|
||||||
* excluded because cleanup itself updates directory ctime)
|
* excluded because cleanup itself updates directory ctime)
|
||||||
|
* - Age 0 removes everything, whatever the timestamps
|
||||||
*/
|
*/
|
||||||
|
if (clean_age) {
|
||||||
if (clean_now - sb->st_mtime < clean_age)
|
if (clean_now - sb->st_mtime < clean_age)
|
||||||
return 0; /* mtime is too new, keep it */
|
return 0; /* mtime is too new, keep it */
|
||||||
|
|
||||||
@@ -423,6 +425,7 @@ static int do_clean(const char *fpath, const struct stat *sb, int tflag, struct
|
|||||||
|
|
||||||
if (!is_dir && clean_now - sb->st_ctime < clean_age)
|
if (!is_dir && clean_now - sb->st_ctime < clean_age)
|
||||||
return 0; /* ctime is too new, keep it (files only) */
|
return 0; /* ctime is too new, keep it (files only) */
|
||||||
|
}
|
||||||
|
|
||||||
if (kept(fpath))
|
if (kept(fpath))
|
||||||
return 0;
|
return 0;
|
||||||
@@ -874,7 +877,7 @@ static void tmpfiles(char *line)
|
|||||||
time_t max_age = parse_age(age);
|
time_t max_age = parse_age(age);
|
||||||
|
|
||||||
/* Only process if age is specified */
|
/* Only process if age is specified */
|
||||||
if (max_age > 0) {
|
if (max_age >= 0) {
|
||||||
switch (type[0]) {
|
switch (type[0]) {
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'D':
|
case 'D':
|
||||||
|
|||||||
@@ -53,3 +53,14 @@ CONF
|
|||||||
assert_left $DIR/keep "all dir "
|
assert_left $DIR/keep "all dir "
|
||||||
assert_left $DIR/keep/all "file "
|
assert_left $DIR/keep/all "file "
|
||||||
assert_left $DIR/keep/dir ""
|
assert_left $DIR/keep/dir ""
|
||||||
|
|
||||||
|
sep
|
||||||
|
say 'Age 0 removes everything, no age nothing'
|
||||||
|
run "mkdir -p $DIR/zero $DIR/none; touch $DIR/zero/file $DIR/none/file"
|
||||||
|
clean <<CONF
|
||||||
|
d $DIR/zero - - - 0
|
||||||
|
d $DIR/none - - - -
|
||||||
|
d $DIR/none
|
||||||
|
CONF
|
||||||
|
assert_left $DIR/zero ""
|
||||||
|
assert_left $DIR/none "file "
|
||||||
Reference in new issue
Block a user