commit ad202c5

default  ·  2022-11-26 04:08:56 +0000 UTC
parent afb970a
Avoid calling time() so many times.
1 files changed,  +3, -4
M data.c
M data.c
+3, -4
 1@@ -1527,11 +1527,9 @@ d_char *dequeue(snac *snac, char *fn)
 2 }
 3 
 4 
 5-static void _purge_file(const char *fn, int days)
 6+static void _purge_file(const char *fn, time_t mt)
 7 /* purge fn if it's older than days */
 8 {
 9-    time_t mt = time(NULL) - days * 24 * 3600;
10-
11     if (mtime(fn) < mt) {
12         /* older than the minimum time: delete it */
13         unlink(fn);
14@@ -1544,13 +1542,14 @@ static void _purge_subdir(snac *snac, const char *subdir, int days)
15 /* purges all files in subdir older than days */
16 {
17     if (days) {
18+        time_t mt = time(NULL) - days * 24 * 3600;
19         xs *spec  = xs_fmt("%s/%s/" "*", snac->basedir, subdir);
20         xs *list  = xs_glob(spec, 0, 0);
21         char *p, *v;
22 
23         p = list;
24         while (xs_list_iter(&p, &v))
25-            _purge_file(v, days);
26+            _purge_file(v, mt);
27     }
28 }
29