From eada63b66f00a376424c2ff55918e028d5c870ec Mon Sep 17 00:00:00 2001 From: grunfink Date: Sun, 11 Oct 2026 18:55:18 +0200 Subject: [PATCH] mastoapi: purge incomplete tokens. --- mastoapi.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/mastoapi.c b/mastoapi.c index 2143ae2..270222e 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -4707,7 +4707,34 @@ void mastoapi_purge(void) if (xs_is_null(uid) || *uid == '\0') { unlink(fn); - srv_debug(2, xs_fmt("purged %s", fn)); + srv_debug(1, xs_fmt("purge incomplete app: %s", fn)); + } + } + } + } + + /* tokens */ + { + xs *spec = xs_fmt("%s/token/" "*.json", srv_basedir); + xs *files = xs_glob(spec, 1, 0); + const char *v; + + xs_list_foreach(files, v) { + FILE *f; + + xs *fn = xs_fmt("%s/token/%s", srv_basedir, v); + + if (mtime(fn) < mt) { + if ((f = fopen(fn, "r")) != NULL) { + xs *token = xs_json_load(f); + fclose(f); + + const char *uid = xs_dict_get(token, "uid"); + + if (xs_is_null(uid) || *uid == '\0') { + unlink(fn); + srv_debug(1, xs_fmt("purge incomplete token: %s", v)); + } } } }