commit a62cde3d9dc074bac6e10d1f3124d6b24d648f63
parent abca46d03745ecf563011f79368d9d162f5637db
Author: default <nobody@localhost>
Date: Tue, 18 Oct 2022 11:40:10 +0200
Rewritten queue() using xs_glob().
Diffstat:
M | data.c | | | 32 | ++++++++++++++------------------ |
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/data.c b/data.c
@@ -978,31 +978,27 @@ void enqueue_output(snac *snac, char *msg, char *actor, int retries)
d_char *queue(snac *snac)
/* returns a list with filenames that can be dequeued */
{
- xs *spec = xs_fmt("%s/queue/" "*.json", snac->basedir);
+ xs *spec = xs_fmt("%s/queue/" "*.json", snac->basedir);
d_char *list = xs_list_new();
- glob_t globbuf;
- time_t t = time(NULL);
+ time_t t = time(NULL);
+ char *p, *v;
- if (glob(spec, 0, NULL, &globbuf) == 0) {
- int n;
- char *p;
+ xs *fns = xs_glob(spec, 0, 0);
- for (n = 0; (p = globbuf.gl_pathv[n]) != NULL; n++) {
- /* get the retry time from the basename */
- char *bn = strrchr(p, '/');
- time_t t2 = atol(bn + 1);
+ p = fns;
+ while (xs_list_iter(&p, &v)) {
+ /* get the retry time from the basename */
+ char *bn = strrchr(v, '/');
+ time_t t2 = atol(bn + 1);
- if (t2 > t)
- snac_debug(snac, 2, xs_fmt("queue not yet time for %s", p));
- else {
- list = xs_list_append(list, p);
- snac_debug(snac, 2, xs_fmt("queue ready for %s", p));
- }
+ if (t2 > t)
+ snac_debug(snac, 2, xs_fmt("queue not yet time for %s", v));
+ else {
+ list = xs_list_append(list, v);
+ snac_debug(snac, 2, xs_fmt("queue ready for %s", v));
}
}
- globfree(&globbuf);
-
return list;
}