diff options
author | Ryan Kavanagh <rak@rak.ac> | 2020-09-11 12:04:51 -0400 |
---|---|---|
committer | Ryan Kavanagh <rak@rak.ac> | 2020-09-11 12:04:51 -0400 |
commit | 539836ef78a77b7741f04d43b38eae667b62fead (patch) | |
tree | 1bac1cb52f40afb01a25937f7966cb2ce914ebaf | |
parent | ptmp: handle files in other directories (diff) |
Add a dryrun flag and treat times as days instead of seconds
Diffstat (limited to '')
-rw-r--r-- | cleanup.c | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -44,14 +44,18 @@ main(int argc, char * const argv[]) double file_age = 0; time_t curr_time = time(NULL); - int verbose, ch; + int verbose, dryrun, ch; verbose = 0; - while ((ch = getopt(argc, argv, "v")) != -1) { + dryrun = 0; + while ((ch = getopt(argc, argv, "vn")) != -1) { switch (ch) { case 'v': verbose = 1; break; + case 'n': + dryrun = 1; + break; } } argc -= optind; @@ -68,14 +72,15 @@ main(int argc, char * const argv[]) case FTS_F: if (stat(node->fts_name, &attr) == -1) err(1, NULL); - file_age = difftime(curr_time, attr.st_mtime); - cutoff = mind + (mind - maxd) * 86400 * - pow((double) attr.st_size / (double) max_size - 1, 3.0); + file_age = difftime(curr_time, attr.st_mtime) / 86400.0; + cutoff = mind + (mind - maxd) * + pow((double) attr.st_size / (double) max_size - 1, 3.0); if (verbose) - printf("%s age %fs cuttoff %fs size %lldB\n", + printf("%s age %fd cuttoff %fd size %lldB\n", node->fts_name, file_age, cutoff, attr.st_size); if (file_age >= cutoff) { - unlink(node->fts_name); + if (!dryrun) + unlink(node->fts_name); if (verbose) printf("%s deleted\n", node->fts_name); } |