summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorGravatar default2023-02-24 10:07:00 +0100
committerGravatar default2023-02-24 10:07:00 +0100
commit3a9ea8aa1cdae74f3434def15052ea1989a130b4 (patch)
tree783aaff51f1fd5733be70a0b91b1d3af74bab36d /data.c
parentIn activitypub_request(), retry failed signed requests as non-signed. (diff)
downloadsnac2-3a9ea8aa1cdae74f3434def15052ea1989a130b4.tar.gz
snac2-3a9ea8aa1cdae74f3434def15052ea1989a130b4.tar.xz
snac2-3a9ea8aa1cdae74f3434def15052ea1989a130b4.zip
Also purge stray index files.
Diffstat (limited to 'data.c')
-rw-r--r--data.c73
1 files changed, 52 insertions, 21 deletions
diff --git a/data.c b/data.c
index 847425c..8469c0f 100644
--- a/data.c
+++ b/data.c
@@ -549,9 +549,6 @@ int _object_add(const char *id, d_char *obj, int ow)
549 /* update the children index of the parent */ 549 /* update the children index of the parent */
550 xs *c_idx = _object_fn(in_reply_to); 550 xs *c_idx = _object_fn(in_reply_to);
551 551
552 if (mtime(c_idx) == 0.0)
553 srv_debug(0, xs_fmt("object_add (warn) parent object not here %s", c_idx));
554
555 c_idx = xs_replace_i(c_idx, ".json", "_c.idx"); 552 c_idx = xs_replace_i(c_idx, ".json", "_c.idx");
556 553
557 if (!index_in(c_idx, id)) { 554 if (!index_in(c_idx, id)) {
@@ -1631,34 +1628,68 @@ void purge_server(void)
1631{ 1628{
1632 xs *spec = xs_fmt("%s/object/??", srv_basedir); 1629 xs *spec = xs_fmt("%s/object/??", srv_basedir);
1633 xs *dirs = xs_glob(spec, 0, 0); 1630 xs *dirs = xs_glob(spec, 0, 0);
1634 char *p, *v; 1631 xs_list *p;
1632 xs_str *v;
1635 int cnt = 0; 1633 int cnt = 0;
1634 int icnt = 0;
1636 1635
1637 time_t mt = time(NULL) - 7 * 24 * 3600; 1636 time_t mt = time(NULL) - 7 * 24 * 3600;
1638 1637
1639 p = dirs; 1638 p = dirs;
1640 while (xs_list_iter(&p, &v)) { 1639 while (xs_list_iter(&p, &v)) {
1641 xs *spec2 = xs_fmt("%s/" "*.json", v); 1640 xs_list *p2;
1642 xs *files = xs_glob(spec2, 0, 0); 1641 xs_str *v2;
1643 char *p2, *v2; 1642
1644 1643 {
1645 p2 = files; 1644 xs *spec2 = xs_fmt("%s/" "*.json", v);
1646 while (xs_list_iter(&p2, &v2)) { 1645 xs *files = xs_glob(spec2, 0, 0);
1647 int n_link; 1646
1648 1647 p2 = files;
1649 /* old and with no hard links? */ 1648 while (xs_list_iter(&p2, &v2)) {
1650 if (mtime_nl(v2, &n_link) < mt && n_link < 2) { 1649 int n_link;
1651 xs *s1 = xs_replace(v2, ".json", ""); 1650
1652 xs *l = xs_split(s1, "/"); 1651 /* old and with no hard links? */
1653 char *md5 = xs_list_get(l, -1); 1652 if (mtime_nl(v2, &n_link) < mt && n_link < 2) {
1654 1653 xs *s1 = xs_replace(v2, ".json", "");
1655 object_del_by_md5(md5); 1654 xs *l = xs_split(s1, "/");
1656 cnt++; 1655 char *md5 = xs_list_get(l, -1);
1656
1657 object_del_by_md5(md5);
1658 cnt++;
1659 }
1660 }
1661 }
1662
1663 {
1664 /* look for stray indexes */
1665 xs *speci = xs_fmt("%s/" "*_?.idx", v);
1666 xs *idxfs = xs_glob(speci, 0, 0);
1667
1668 p2 = idxfs;
1669 while (xs_list_iter(&p2, &v2)) {
1670 /* old enough to consider? */
1671 if (mtime(v2) < mt) {
1672 /* check if the indexed object is here */
1673 xs *o = xs_dup(v2);
1674 char *ext = strchr(o, '_');
1675
1676 if (ext) {
1677 *ext = '\0';
1678 o = xs_str_cat(o, ".json");
1679
1680 if (mtime(o) == 0.0) {
1681 /* delete */
1682 unlink(v2);
1683 srv_debug(1, xs_fmt("purged %s", v2));
1684 icnt++;
1685 }
1686 }
1687 }
1657 } 1688 }
1658 } 1689 }
1659 } 1690 }
1660 1691
1661 srv_debug(0, xs_fmt("purge: global %d", cnt)); 1692 srv_debug(0, xs_fmt("purge: global (obj: %d, idx: %d)", cnt, icnt));
1662} 1693}
1663 1694
1664 1695