mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
tmpfiles: add --dry-run, to show what would be run
There was no way to see what the tmpfiles.d files on a system amount
to, short of running them:
tmpfiles --dry-run --create --remove --boot
With -n or --dry-run each entry that would be run is printed, with
what would be done, remove, clean, or create, in the order it would
be. Nothing is changed.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
5 files changed
+47
-5
No files matched your search
+24
-1
@@ -61,6 +61,7 @@ int create_flag = 0;
|
||||
int clean_flag = 0;
|
||||
int remove_flag = 0;
|
||||
int boot_flag = 0;
|
||||
int dry_run = 0;
|
||||
|
||||
/* Set for the first of two passes, the second one does the complaining */
|
||||
static int quiet;
|
||||
@@ -1469,6 +1470,22 @@ static void tmpfiles(char *line)
|
||||
}
|
||||
}
|
||||
|
||||
if (dry_run) {
|
||||
if (!strchr("aAbcCdDefFhHlLprRtTwxXzZ", type[0])) {
|
||||
if (!quiet)
|
||||
warnx("Unsupported tmpfiles command '%s', skipping %s", type, path);
|
||||
return;
|
||||
}
|
||||
|
||||
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))
|
||||
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 ? " " : "", arg ?: "");
|
||||
return;
|
||||
}
|
||||
|
||||
strc = stat(path, &st);
|
||||
|
||||
// file and directory removal logic
|
||||
@@ -1878,6 +1895,7 @@ static int usage(int rc)
|
||||
" -C, --clean Clean files and directories based on age\n"
|
||||
" -c, --create Create files and directories\n"
|
||||
" -d, --debug Show developer debug messages\n"
|
||||
" -n, --dry-run Only show the entries that would be run\n"
|
||||
" -E Exclude /dev, /proc, /run, and /sys\n"
|
||||
" --exclude-prefix=PFX Ignore rules for paths starting with PFX\n"
|
||||
" --prefix=PFX Only apply rules for paths starting with PFX\n"
|
||||
@@ -1904,6 +1922,7 @@ int main(int argc, char *argv[])
|
||||
{ "clean", 0, NULL, 'C' },
|
||||
{ "create", 0, NULL, 'c' },
|
||||
{ "debug", 0, NULL, 'd' },
|
||||
{ "dry-run", 0, NULL, 'n' },
|
||||
{ "exclude-prefix", 1, NULL, OPT_EXCLUDE_PREFIX },
|
||||
{ "prefix", 1, NULL, OPT_PREFIX },
|
||||
{ "remove", 0, NULL, 'r' },
|
||||
@@ -1913,7 +1932,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
int c;
|
||||
|
||||
while ((c = getopt_long(argc, argv, "CcdrEh?", long_options, NULL)) != EOF) {
|
||||
while ((c = getopt_long(argc, argv, "CcdnrEh?", long_options, NULL)) != EOF) {
|
||||
switch(c) {
|
||||
case 'C':
|
||||
clean_flag = 1;
|
||||
@@ -1927,6 +1946,10 @@ int main(int argc, char *argv[])
|
||||
debug = 1;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
dry_run = 1;
|
||||
break;
|
||||
|
||||
case 'E':
|
||||
add_exclude_prefix("/dev");
|
||||
add_exclude_prefix("/proc");
|
||||
|
||||
Reference in new issue
Block a user