summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'data.c')
-rw-r--r--data.c56
1 files changed, 26 insertions, 30 deletions
diff --git a/data.c b/data.c
index 741acc8..cb55415 100644
--- a/data.c
+++ b/data.c
@@ -1130,42 +1130,38 @@ d_char *dequeue(snac *snac, char *fn)
}
-void purge(snac *snac)
-/* do the purge */
+static void _purge_subdir(snac *snac, const char *subdir, int days)
+/* purges all files in subdir older than days */
{
- int tpd = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days"));
-
- /* purge days set to 0? disable purging */
- if (tpd == 0) {
- /* well, enjoy your data drive exploding */
- return;
+ if (days) {
+ time_t mt = time(NULL) - days * 24 * 3600;
+ xs *spec = xs_fmt("%s/%s/" "*.json", 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));
+ }
+ }
}
+}
- time_t mt = time(NULL) - tpd * 24 * 3600;
- xs *t_spec = xs_fmt("%s/timeline/" "*.json", snac->basedir);
- xs *t_list = xs_glob(t_spec, 0, 0);
- char *p, *v;
- p = t_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));
- }
- }
+void purge(snac *snac)
+/* do the purge */
+{
+ int days;
- xs *a_spec = xs_fmt("%s/actors/" "*.json", snac->basedir);
- xs *a_list = xs_glob(a_spec, 0, 0);
+ days = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days"));
+ _purge_subdir(snac, "timeline", days);
+ _purge_subdir(snac, "actors", days);
- p = a_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));
- }
- }
+ days = xs_number_get(xs_dict_get(srv_config, "local_purge_days"));
+ _purge_subdir(snac, "local", days);
}