mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 19:50:26 +03:00
Avoid calling time() so many times.
This commit is contained in:
parent
afb970a757
commit
ad202c5ccb
7
data.c
7
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 */
|
/* purge fn if it's older than days */
|
||||||
{
|
{
|
||||||
time_t mt = time(NULL) - days * 24 * 3600;
|
|
||||||
|
|
||||||
if (mtime(fn) < mt) {
|
if (mtime(fn) < mt) {
|
||||||
/* older than the minimum time: delete it */
|
/* older than the minimum time: delete it */
|
||||||
unlink(fn);
|
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 */
|
/* purges all files in subdir older than days */
|
||||||
{
|
{
|
||||||
if (days) {
|
if (days) {
|
||||||
|
time_t mt = time(NULL) - days * 24 * 3600;
|
||||||
xs *spec = xs_fmt("%s/%s/" "*", snac->basedir, subdir);
|
xs *spec = xs_fmt("%s/%s/" "*", snac->basedir, subdir);
|
||||||
xs *list = xs_glob(spec, 0, 0);
|
xs *list = xs_glob(spec, 0, 0);
|
||||||
char *p, *v;
|
char *p, *v;
|
||||||
|
|
||||||
p = list;
|
p = list;
|
||||||
while (xs_list_iter(&p, &v))
|
while (xs_list_iter(&p, &v))
|
||||||
_purge_file(v, days);
|
_purge_file(v, mt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user