Also purge stray index files.

This commit is contained in:
default 2023-02-24 10:07:00 +01:00
parent 1d82d13d62
commit 3a9ea8aa1c

43
data.c
View file

@ -549,9 +549,6 @@ int _object_add(const char *id, d_char *obj, int ow)
/* update the children index of the parent */
xs *c_idx = _object_fn(in_reply_to);
if (mtime(c_idx) == 0.0)
srv_debug(0, xs_fmt("object_add (warn) parent object not here %s", c_idx));
c_idx = xs_replace_i(c_idx, ".json", "_c.idx");
if (!index_in(c_idx, id)) {
@ -1631,16 +1628,21 @@ void purge_server(void)
{
xs *spec = xs_fmt("%s/object/??", srv_basedir);
xs *dirs = xs_glob(spec, 0, 0);
char *p, *v;
xs_list *p;
xs_str *v;
int cnt = 0;
int icnt = 0;
time_t mt = time(NULL) - 7 * 24 * 3600;
p = dirs;
while (xs_list_iter(&p, &v)) {
xs_list *p2;
xs_str *v2;
{
xs *spec2 = xs_fmt("%s/" "*.json", v);
xs *files = xs_glob(spec2, 0, 0);
char *p2, *v2;
p2 = files;
while (xs_list_iter(&p2, &v2)) {
@ -1658,7 +1660,36 @@ void purge_server(void)
}
}
srv_debug(0, xs_fmt("purge: global %d", cnt));
{
/* look for stray indexes */
xs *speci = xs_fmt("%s/" "*_?.idx", v);
xs *idxfs = xs_glob(speci, 0, 0);
p2 = idxfs;
while (xs_list_iter(&p2, &v2)) {
/* old enough to consider? */
if (mtime(v2) < mt) {
/* check if the indexed object is here */
xs *o = xs_dup(v2);
char *ext = strchr(o, '_');
if (ext) {
*ext = '\0';
o = xs_str_cat(o, ".json");
if (mtime(o) == 0.0) {
/* delete */
unlink(v2);
srv_debug(1, xs_fmt("purged %s", v2));
icnt++;
}
}
}
}
}
}
srv_debug(0, xs_fmt("purge: global (obj: %d, idx: %d)", cnt, icnt));
}