diff options
| -rw-r--r-- | data.c | 56 | ||||
| -rw-r--r-- | utils.c | 3 |
2 files changed, 28 insertions, 31 deletions
| @@ -1130,42 +1130,38 @@ d_char *dequeue(snac *snac, char *fn) | |||
| 1130 | } | 1130 | } |
| 1131 | 1131 | ||
| 1132 | 1132 | ||
| 1133 | void purge(snac *snac) | 1133 | static void _purge_subdir(snac *snac, const char *subdir, int days) |
| 1134 | /* do the purge */ | 1134 | /* purges all files in subdir older than days */ |
| 1135 | { | 1135 | { |
| 1136 | int tpd = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days")); | 1136 | if (days) { |
| 1137 | 1137 | time_t mt = time(NULL) - days * 24 * 3600; | |
| 1138 | /* purge days set to 0? disable purging */ | 1138 | xs *spec = xs_fmt("%s/%s/" "*.json", snac->basedir, subdir); |
| 1139 | if (tpd == 0) { | 1139 | xs *list = xs_glob(spec, 0, 0); |
| 1140 | /* well, enjoy your data drive exploding */ | 1140 | char *p, *v; |
| 1141 | return; | 1141 | |
| 1142 | p = list; | ||
| 1143 | while (xs_list_iter(&p, &v)) { | ||
| 1144 | if (mtime(v) < mt) { | ||
| 1145 | /* older than the minimum time: delete it */ | ||
| 1146 | unlink(v); | ||
| 1147 | snac_debug(snac, 1, xs_fmt("purged %s", v)); | ||
| 1148 | } | ||
| 1149 | } | ||
| 1142 | } | 1150 | } |
| 1151 | } | ||
| 1143 | 1152 | ||
| 1144 | time_t mt = time(NULL) - tpd * 24 * 3600; | ||
| 1145 | xs *t_spec = xs_fmt("%s/timeline/" "*.json", snac->basedir); | ||
| 1146 | xs *t_list = xs_glob(t_spec, 0, 0); | ||
| 1147 | char *p, *v; | ||
| 1148 | 1153 | ||
| 1149 | p = t_list; | 1154 | void purge(snac *snac) |
| 1150 | while (xs_list_iter(&p, &v)) { | 1155 | /* do the purge */ |
| 1151 | if (mtime(v) < mt) { | 1156 | { |
| 1152 | /* older than the minimum time: delete it */ | 1157 | int days; |
| 1153 | unlink(v); | ||
| 1154 | snac_debug(snac, 1, xs_fmt("purged %s", v)); | ||
| 1155 | } | ||
| 1156 | } | ||
| 1157 | 1158 | ||
| 1158 | xs *a_spec = xs_fmt("%s/actors/" "*.json", snac->basedir); | 1159 | days = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days")); |
| 1159 | xs *a_list = xs_glob(a_spec, 0, 0); | 1160 | _purge_subdir(snac, "timeline", days); |
| 1161 | _purge_subdir(snac, "actors", days); | ||
| 1160 | 1162 | ||
| 1161 | p = a_list; | 1163 | days = xs_number_get(xs_dict_get(srv_config, "local_purge_days")); |
| 1162 | while (xs_list_iter(&p, &v)) { | 1164 | _purge_subdir(snac, "local", days); |
| 1163 | if (mtime(v) < mt) { | ||
| 1164 | /* older than the minimum time: delete it */ | ||
| 1165 | unlink(v); | ||
| 1166 | snac_debug(snac, 1, xs_fmt("purged %s", v)); | ||
| 1167 | } | ||
| 1168 | } | ||
| 1169 | } | 1165 | } |
| 1170 | 1166 | ||
| 1171 | 1167 | ||
| @@ -24,7 +24,8 @@ const char *default_srv_config = "{" | |||
| 24 | "\"queue_retry_max\": 10," | 24 | "\"queue_retry_max\": 10," |
| 25 | "\"cssurls\": [\"\"]," | 25 | "\"cssurls\": [\"\"]," |
| 26 | "\"max_timeline_entries\": 256," | 26 | "\"max_timeline_entries\": 256," |
| 27 | "\"timeline_purge_days\": 120" | 27 | "\"timeline_purge_days\": 120," |
| 28 | "\"local_purge_days\": 0" | ||
| 28 | "}"; | 29 | "}"; |
| 29 | 30 | ||
| 30 | const char *default_css = | 31 | const char *default_css = |