diff options
author | Ryan Kavanagh <rak@rak.ac> | 2020-09-11 12:23:26 -0400 |
---|---|---|
committer | Ryan Kavanagh <rak@rak.ac> | 2020-09-11 12:23:26 -0400 |
commit | e6af32a76a931d3669ea5fee930f1bc6f59226f3 (patch) | |
tree | 505d5168b288348c125b04fd5241ebb2d4cd3017 | |
parent | Add a dryrun flag and treat times as days instead of seconds (diff) |
use fts_nochdir
-rw-r--r-- | cleanup.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -61,7 +61,7 @@ main(int argc, char * const argv[]) argc -= optind; argv += optind; - if ((file_system = fts_open(paths, 0, NULL)) == NULL) + if ((file_system = fts_open(paths, FTS_NOCHDIR, NULL)) == NULL) errx(1, NULL); while ((node = fts_read(file_system)) != NULL) { @@ -70,19 +70,22 @@ main(int argc, char * const argv[]) switch (node->fts_info) { case FTS_F: - if (stat(node->fts_name, &attr) == -1) + if (stat(node->fts_path, &attr) == -1) err(1, NULL); + if (strcmp(node->fts_name, exclude) == 0) { + break; + } 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 %fd cuttoff %fd size %lldB\n", - node->fts_name, file_age, cutoff, attr.st_size); + node->fts_path, file_age, cutoff, attr.st_size); if (file_age >= cutoff) { if (!dryrun) - unlink(node->fts_name); + unlink(node->fts_path); if (verbose) - printf("%s deleted\n", node->fts_name); + printf("%s deleted\n", node->fts_path); } break; default: |