summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorGravatar default2022-11-26 05:08:56 +0100
committerGravatar default2022-11-26 05:08:56 +0100
commitad202c5ccb8b3cbcb30c3b15e1e129652ea910d9 (patch)
tree5523d4b995c71938aa26d0df75afe2c3271c122f /data.c
parentpurge_server() deletes using object_del(). (diff)
downloadsnac2-ad202c5ccb8b3cbcb30c3b15e1e129652ea910d9.tar.gz
snac2-ad202c5ccb8b3cbcb30c3b15e1e129652ea910d9.tar.xz
snac2-ad202c5ccb8b3cbcb30c3b15e1e129652ea910d9.zip
Avoid calling time() so many times.
Diffstat (limited to 'data.c')
-rw-r--r--data.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/data.c b/data.c
index 938f0e0..3b7ac58 100644
--- a/data.c
+++ b/data.c
@@ -1527,11 +1527,9 @@ d_char *dequeue(snac *snac, char *fn)
1527} 1527}
1528 1528
1529 1529
1530static void _purge_file(const char *fn, int days) 1530static void _purge_file(const char *fn, time_t mt)
1531/* purge fn if it's older than days */ 1531/* purge fn if it's older than days */
1532{ 1532{
1533 time_t mt = time(NULL) - days * 24 * 3600;
1534
1535 if (mtime(fn) < mt) { 1533 if (mtime(fn) < mt) {
1536 /* older than the minimum time: delete it */ 1534 /* older than the minimum time: delete it */
1537 unlink(fn); 1535 unlink(fn);
@@ -1544,13 +1542,14 @@ static void _purge_subdir(snac *snac, const char *subdir, int days)
1544/* purges all files in subdir older than days */ 1542/* purges all files in subdir older than days */
1545{ 1543{
1546 if (days) { 1544 if (days) {
1545 time_t mt = time(NULL) - days * 24 * 3600;
1547 xs *spec = xs_fmt("%s/%s/" "*", snac->basedir, subdir); 1546 xs *spec = xs_fmt("%s/%s/" "*", snac->basedir, subdir);
1548 xs *list = xs_glob(spec, 0, 0); 1547 xs *list = xs_glob(spec, 0, 0);
1549 char *p, *v; 1548 char *p, *v;
1550 1549
1551 p = list; 1550 p = list;
1552 while (xs_list_iter(&p, &v)) 1551 while (xs_list_iter(&p, &v))
1553 _purge_file(v, days); 1552 _purge_file(v, mt);
1554 } 1553 }
1555} 1554}
1556 1555