commit 3a9ea8a
default
·
2023-02-24 09:07:00 +0000 UTC
parent 1d82d13
Also purge stray index files.
1 files changed,
+52,
-21
M
data.c
M
data.c
+52,
-21
1@@ -549,9 +549,6 @@ int _object_add(const char *id, d_char *obj, int ow)
2 /* update the children index of the parent */
3 xs *c_idx = _object_fn(in_reply_to);
4
5- if (mtime(c_idx) == 0.0)
6- srv_debug(0, xs_fmt("object_add (warn) parent object not here %s", c_idx));
7-
8 c_idx = xs_replace_i(c_idx, ".json", "_c.idx");
9
10 if (!index_in(c_idx, id)) {
11@@ -1631,34 +1628,68 @@ void purge_server(void)
12 {
13 xs *spec = xs_fmt("%s/object/??", srv_basedir);
14 xs *dirs = xs_glob(spec, 0, 0);
15- char *p, *v;
16+ xs_list *p;
17+ xs_str *v;
18 int cnt = 0;
19+ int icnt = 0;
20
21 time_t mt = time(NULL) - 7 * 24 * 3600;
22
23 p = dirs;
24 while (xs_list_iter(&p, &v)) {
25- xs *spec2 = xs_fmt("%s/" "*.json", v);
26- xs *files = xs_glob(spec2, 0, 0);
27- char *p2, *v2;
28-
29- p2 = files;
30- while (xs_list_iter(&p2, &v2)) {
31- int n_link;
32-
33- /* old and with no hard links? */
34- if (mtime_nl(v2, &n_link) < mt && n_link < 2) {
35- xs *s1 = xs_replace(v2, ".json", "");
36- xs *l = xs_split(s1, "/");
37- char *md5 = xs_list_get(l, -1);
38-
39- object_del_by_md5(md5);
40- cnt++;
41+ xs_list *p2;
42+ xs_str *v2;
43+
44+ {
45+ xs *spec2 = xs_fmt("%s/" "*.json", v);
46+ xs *files = xs_glob(spec2, 0, 0);
47+
48+ p2 = files;
49+ while (xs_list_iter(&p2, &v2)) {
50+ int n_link;
51+
52+ /* old and with no hard links? */
53+ if (mtime_nl(v2, &n_link) < mt && n_link < 2) {
54+ xs *s1 = xs_replace(v2, ".json", "");
55+ xs *l = xs_split(s1, "/");
56+ char *md5 = xs_list_get(l, -1);
57+
58+ object_del_by_md5(md5);
59+ cnt++;
60+ }
61+ }
62+ }
63+
64+ {
65+ /* look for stray indexes */
66+ xs *speci = xs_fmt("%s/" "*_?.idx", v);
67+ xs *idxfs = xs_glob(speci, 0, 0);
68+
69+ p2 = idxfs;
70+ while (xs_list_iter(&p2, &v2)) {
71+ /* old enough to consider? */
72+ if (mtime(v2) < mt) {
73+ /* check if the indexed object is here */
74+ xs *o = xs_dup(v2);
75+ char *ext = strchr(o, '_');
76+
77+ if (ext) {
78+ *ext = '\0';
79+ o = xs_str_cat(o, ".json");
80+
81+ if (mtime(o) == 0.0) {
82+ /* delete */
83+ unlink(v2);
84+ srv_debug(1, xs_fmt("purged %s", v2));
85+ icnt++;
86+ }
87+ }
88+ }
89 }
90 }
91 }
92
93- srv_debug(0, xs_fmt("purge: global %d", cnt));
94+ srv_debug(0, xs_fmt("purge: global (obj: %d, idx: %d)", cnt, icnt));
95 }
96
97