summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-11-26 05:08:56 +0100
committerdefault <nobody@localhost>2022-11-26 05:08:56 +0100
commitad202c5ccb8b3cbcb30c3b15e1e129652ea910d9 (patch)
tree5523d4b995c71938aa26d0df75afe2c3271c122f /data.c
parentafb970a757c67332d34a987d7bc7e4b0e3710932 (diff)
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)
}
-static void _purge_file(const char *fn, int days)
+static void _purge_file(const char *fn, time_t mt)
/* purge fn if it's older than days */
{
- time_t mt = time(NULL) - days * 24 * 3600;
-
if (mtime(fn) < mt) {
/* older than the minimum time: delete it */
unlink(fn);
@@ -1544,13 +1542,14 @@ static void _purge_subdir(snac *snac, const char *subdir, int days)
/* purges all files in subdir older than days */
{
if (days) {
+ time_t mt = time(NULL) - days * 24 * 3600;
xs *spec = xs_fmt("%s/%s/" "*", snac->basedir, subdir);
xs *list = xs_glob(spec, 0, 0);
char *p, *v;
p = list;
while (xs_list_iter(&p, &v))
- _purge_file(v, days);
+ _purge_file(v, mt);
}
}