summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-11-25 11:37:05 +0100
committerdefault <nobody@localhost>2022-11-25 11:37:05 +0100
commit200a6a0c91b8c4132aacf4eca9033a74ce3dfc8e (patch)
treef7e6a954da0c1af65d6f2e6d61f12d4dfdc867d2
parentb79241701385c33b58359adfa20bbadb643b86b9 (diff)
The global object database is also purged.
-rw-r--r--data.c47
-rw-r--r--snac.h2
2 files changed, 40 insertions, 9 deletions
diff --git a/data.c b/data.c
index bcfdd9b..15ca18d 100644
--- 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
index bdbdade..be8aaae 100644
--- 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);