From e6af32a76a931d3669ea5fee930f1bc6f59226f3 Mon Sep 17 00:00:00 2001 From: Ryan Kavanagh Date: Fri, 11 Sep 2020 12:23:26 -0400 Subject: use fts_nochdir --- cleanup.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cleanup.c b/cleanup.c index 3dd6e36..f708900 100644 --- a/cleanup.c +++ b/cleanup.c @@ -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: -- cgit v1.2.3