mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-12-24 00:23:38 +00:00
Incomplete mastoapi apps are purged.
This commit is contained in:
parent
765f63772f
commit
d0e08277da
1 changed files with 35 additions and 2 deletions
37
mastoapi.c
37
mastoapi.c
|
@ -9,6 +9,7 @@
|
|||
#include "xs_json.h"
|
||||
#include "xs_io.h"
|
||||
#include "xs_time.h"
|
||||
#include "xs_glob.h"
|
||||
|
||||
#include "snac.h"
|
||||
|
||||
|
@ -59,13 +60,19 @@ int app_add(const char *id, const xs_dict *app)
|
|||
}
|
||||
|
||||
|
||||
xs_str *_app_fn(const char *id)
|
||||
{
|
||||
return xs_fmt("%s/app/%s.json", srv_basedir, id);
|
||||
}
|
||||
|
||||
|
||||
xs_dict *app_get(const char *id)
|
||||
/* gets an app */
|
||||
{
|
||||
if (!xs_is_hex(id))
|
||||
return NULL;
|
||||
|
||||
xs *fn = xs_fmt("%s/app/%s.json", srv_basedir, id);
|
||||
xs *fn = _app_fn(id);
|
||||
xs_dict *app = NULL;
|
||||
FILE *f;
|
||||
|
||||
|
@ -86,7 +93,7 @@ int app_del(const char *id)
|
|||
if (!xs_is_hex(id))
|
||||
return -1;
|
||||
|
||||
xs *fn = xs_fmt("%s/app/%s.json", srv_basedir, id);
|
||||
xs *fn = _app_fn(id);
|
||||
|
||||
return unlink(fn);
|
||||
}
|
||||
|
@ -1963,6 +1970,32 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
|
|||
|
||||
void mastoapi_purge(void)
|
||||
{
|
||||
xs *spec = xs_fmt("%s/app/" "*.json", srv_basedir);
|
||||
xs *files = xs_glob(spec, 1, 0);
|
||||
xs_list *p = files;
|
||||
xs_str *v;
|
||||
|
||||
time_t mt = time(NULL) - 3600;
|
||||
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
xs *cid = xs_replace(v, ".json", "");
|
||||
xs *fn = _app_fn(cid);
|
||||
|
||||
if (mtime(fn) < mt) {
|
||||
/* get the app */
|
||||
xs *app = app_get(cid);
|
||||
|
||||
if (app) {
|
||||
/* old apps with no uid are incomplete cruft */
|
||||
const char *uid = xs_dict_get(app, "uid");
|
||||
|
||||
if (xs_is_null(uid) || *uid == '\0') {
|
||||
unlink(fn);
|
||||
srv_debug(2, xs_fmt("purged %s", fn));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue