diff options
| author | 2022-10-04 18:46:12 +0200 | |
|---|---|---|
| committer | 2022-10-04 18:46:12 +0200 | |
| commit | ae06064e4d77d10b82c6061427dcc01d942b1dd8 (patch) | |
| tree | 6da9cbb635f377f908e2a442cb122dc6a8f42b8a /data.c | |
| parent | Fixed bug in the entry children popup. (diff) | |
| download | snac2-ae06064e4d77d10b82c6061427dcc01d942b1dd8.tar.gz snac2-ae06064e4d77d10b82c6061427dcc01d942b1dd8.tar.xz snac2-ae06064e4d77d10b82c6061427dcc01d942b1dd8.zip | |
New command-line option purge.
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 33 |
1 files changed, 33 insertions, 0 deletions
| @@ -996,3 +996,36 @@ d_char *dequeue(snac *snac, char *fn) | |||
| 996 | 996 | ||
| 997 | return obj; | 997 | return obj; |
| 998 | } | 998 | } |
| 999 | |||
| 1000 | |||
| 1001 | void purge(snac *snac) | ||
| 1002 | /* do the purge */ | ||
| 1003 | { | ||
| 1004 | int tpd = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days")); | ||
| 1005 | time_t mt = time(NULL) - tpd * 24 * 3600; | ||
| 1006 | char *p, *v; | ||
| 1007 | |||
| 1008 | xs *t_spec = xs_fmt("%s/timeline/" "*.json", snac->basedir); | ||
| 1009 | xs *t_list = xs_glob(t_spec, 0, 0); | ||
| 1010 | |||
| 1011 | p = t_list; | ||
| 1012 | while (xs_list_iter(&p, &v)) { | ||
| 1013 | if (mtime(v) < mt) { | ||
| 1014 | /* older than the minimum time: delete it */ | ||
| 1015 | unlink(v); | ||
| 1016 | snac_debug(snac, 1, xs_fmt("purged %s", v)); | ||
| 1017 | } | ||
| 1018 | } | ||
| 1019 | |||
| 1020 | xs *a_spec = xs_fmt("%s/actors/" "*.json", snac->basedir); | ||
| 1021 | xs *a_list = xs_glob(a_spec, 0, 0); | ||
| 1022 | |||
| 1023 | p = a_list; | ||
| 1024 | while (xs_list_iter(&p, &v)) { | ||
| 1025 | if (mtime(v) < mt) { | ||
| 1026 | /* older than the minimum time: delete it */ | ||
| 1027 | unlink(v); | ||
| 1028 | snac_debug(snac, 1, xs_fmt("purged %s", v)); | ||
| 1029 | } | ||
| 1030 | } | ||
| 1031 | } | ||