commit 200a6a0
default
·
2022-11-25 10:37:05 +0000 UTC
parent b792417
The global object database is also purged.
M
data.c
+39,
-8
1@@ -185,7 +185,7 @@ d_char *user_list(void)
2 }
3
4
5-double mtime(char *fn)
6+double mtime(const char *fn)
7 /* returns the mtime of a file or directory, or 0.0 */
8 {
9 struct stat st;
10@@ -1477,22 +1477,51 @@ d_char *dequeue(snac *snac, char *fn)
11 }
12
13
14+static void _purge_file(const char *fn, int days)
15+{
16+ time_t mt = time(NULL) - days * 24 * 3600;
17+
18+ if (mtime(fn) < mt) {
19+ /* older than the minimum time: delete it */
20+ unlink(fn);
21+ srv_debug(1, xs_fmt("purged %s", fn));
22+ }
23+}
24+
25+
26 static void _purge_subdir(snac *snac, const char *subdir, int days)
27 /* purges all files in subdir older than days */
28 {
29 if (days) {
30- time_t mt = time(NULL) - days * 24 * 3600;
31 xs *spec = xs_fmt("%s/%s/" "*", snac->basedir, subdir);
32 xs *list = xs_glob(spec, 0, 0);
33 char *p, *v;
34
35 p = list;
36- while (xs_list_iter(&p, &v)) {
37- if (mtime(v) < mt) {
38- /* older than the minimum time: delete it */
39- unlink(v);
40- snac_debug(snac, 1, xs_fmt("purged %s", v));
41- }
42+ while (xs_list_iter(&p, &v))
43+ _purge_file(v, days);
44+ }
45+}
46+
47+
48+void purge_server(void)
49+/* purge global server data */
50+{
51+ int tpd = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days"));
52+// int lpd = xs_number_get(xs_dict_get(srv_config, "local_purge_days"));
53+ xs *spec = xs_fmt("%s/object/??", srv_basedir);
54+ xs *dirs = xs_glob(spec, 0, 0);
55+ char *p, *v;
56+
57+ p = dirs;
58+ while (xs_list_iter(&p, &v)) {
59+ xs *spec2 = xs_fmt("%s/" "*", v);
60+ xs *files = xs_glob(spec2, 0, 0);
61+ char *p2, *v2;
62+
63+ p2 = files;
64+ while (xs_list_iter(&p2, &v2)) {
65+ _purge_file(v2, tpd);
66 }
67 }
68 }
69@@ -1515,6 +1544,8 @@ void purge_user(snac *snac)
70 void purge_all(void)
71 /* purge all users */
72 {
73+ purge_server();
74+
75 snac snac;
76 xs *list = user_list();
77 char *p, *uid;
M
snac.h
+1,
-1
1@@ -50,7 +50,7 @@ int check_password(char *uid, char *passwd, char *hash);
2 void srv_archive(char *direction, char *req, char *payload, int p_size,
3 int status, char *headers, char *body, int b_size);
4
5-double mtime(char *fn);
6+double mtime(const char *fn);
7
8 int index_add(const char *fn, const char *md5);
9 int index_del(const char *fn, const char *md5);