aboutsummaryrefslogtreecommitdiff
path: root/cleanup.c
diff options
context:
space:
mode:
Diffstat (limited to 'cleanup.c')
-rw-r--r--cleanup.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/cleanup.c b/cleanup.c
index 429c8c2..3dd6e36 100644
--- a/cleanup.c
+++ b/cleanup.c
@@ -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);
}