commit 200a6a0c91b8c4132aacf4eca9033a74ce3dfc8e
parent b79241701385c33b58359adfa20bbadb643b86b9
Author: default <nobody@localhost>
Date: Fri, 25 Nov 2022 11:37:05 +0100
The global object database is also purged.
Diffstat:
M | data.c | | | 47 | +++++++++++++++++++++++++++++++++++++++-------- |
M | snac.h | | | 2 | +- |
2 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/data.c b/data.c
@@ -185,7 +185,7 @@ d_char *user_list(void)
}
-double mtime(char *fn)
+double mtime(const char *fn)
/* returns the mtime of a file or directory, or 0.0 */
{
struct stat st;
@@ -1477,22 +1477,51 @@ d_char *dequeue(snac *snac, char *fn)
}
+static void _purge_file(const char *fn, int days)
+{
+ time_t mt = time(NULL) - days * 24 * 3600;
+
+ if (mtime(fn) < mt) {
+ /* older than the minimum time: delete it */
+ unlink(fn);
+ srv_debug(1, xs_fmt("purged %s", fn));
+ }
+}
+
+
static void _purge_subdir(snac *snac, const char *subdir, int days)
/* purges all files in subdir older than days */
{
if (days) {
- time_t mt = time(NULL) - days * 24 * 3600;
xs *spec = xs_fmt("%s/%s/" "*", snac->basedir, subdir);
xs *list = xs_glob(spec, 0, 0);
char *p, *v;
p = list;
- while (xs_list_iter(&p, &v)) {
- if (mtime(v) < mt) {
- /* older than the minimum time: delete it */
- unlink(v);
- snac_debug(snac, 1, xs_fmt("purged %s", v));
- }
+ while (xs_list_iter(&p, &v))
+ _purge_file(v, days);
+ }
+}
+
+
+void purge_server(void)
+/* purge global server data */
+{
+ int tpd = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days"));
+// int lpd = xs_number_get(xs_dict_get(srv_config, "local_purge_days"));
+ xs *spec = xs_fmt("%s/object/??", srv_basedir);
+ xs *dirs = xs_glob(spec, 0, 0);
+ char *p, *v;
+
+ p = dirs;
+ while (xs_list_iter(&p, &v)) {
+ xs *spec2 = xs_fmt("%s/" "*", v);
+ xs *files = xs_glob(spec2, 0, 0);
+ char *p2, *v2;
+
+ p2 = files;
+ while (xs_list_iter(&p2, &v2)) {
+ _purge_file(v2, tpd);
}
}
}
@@ -1515,6 +1544,8 @@ void purge_user(snac *snac)
void purge_all(void)
/* purge all users */
{
+ purge_server();
+
snac snac;
xs *list = user_list();
char *p, *uid;
diff --git a/snac.h b/snac.h
@@ -50,7 +50,7 @@ int check_password(char *uid, char *passwd, char *hash);
void srv_archive(char *direction, char *req, char *payload, int p_size,
int status, char *headers, char *body, int b_size);
-double mtime(char *fn);
+double mtime(const char *fn);
int index_add(const char *fn, const char *md5);
int index_del(const char *fn, const char *md5);