diff --git a/data.c b/data.c index b19d1c6..23a82af 100644 --- a/data.c +++ b/data.c @@ -996,3 +996,36 @@ d_char *dequeue(snac *snac, char *fn) return obj; } + + +void purge(snac *snac) +/* do the purge */ +{ + int tpd = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days")); + time_t mt = time(NULL) - tpd * 24 * 3600; + char *p, *v; + + xs *t_spec = xs_fmt("%s/timeline/" "*.json", snac->basedir); + xs *t_list = xs_glob(t_spec, 0, 0); + + 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)); + } + } + + xs *a_spec = xs_fmt("%s/actors/" "*.json", snac->basedir); + xs *a_list = xs_glob(a_spec, 0, 0); + + 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)); + } + } +} diff --git a/main.c b/main.c index 18c7c22..52eca27 100644 --- a/main.c +++ b/main.c @@ -18,12 +18,12 @@ int usage(void) printf("init [{basedir}] Initializes the database\n"); printf("adduser {basedir} [{uid}] Adds a new user\n"); printf("httpd {basedir} Starts the HTTPD daemon\n"); + printf("purge {basedir} Purges old data\n"); printf("webfinger {basedir} {user} Queries about a @user@host or actor\n"); printf("queue {basedir} {uid} Processes a user queue\n"); printf("follow {basedir} {uid} {actor} Follows an actor\n"); // printf("check {basedir} [{uid}] Checks the database\n"); -// printf("purge {basedir} [{uid}] Purges old data\n"); // printf("update {basedir} {uid} Sends a user update to followers\n"); // printf("passwd {basedir} {uid} Sets the password for {uid}\n"); @@ -95,6 +95,22 @@ int main(int argc, char *argv[]) return 0; } + if (strcmp(cmd, "purge") == 0) { + /* iterate all users */ + xs *list = user_list(); + char *p, *uid; + + p = list; + while (xs_list_iter(&p, &uid)) { + if (user_open(&snac, uid)) { + purge(&snac); + user_free(&snac); + } + } + + return 0; + } + if ((user = GET_ARGV()) == NULL) return usage(); diff --git a/snac.h b/snac.h index 9a387ad..365115c 100644 --- a/snac.h +++ b/snac.h @@ -94,6 +94,8 @@ void enqueue_output(snac *snac, char *msg, char *actor, int retries); d_char *queue(snac *snac); d_char *dequeue(snac *snac, char *fn); +void purge(snac *snac); + d_char *http_signed_request(snac *snac, char *method, char *url, d_char *headers, d_char *body, int b_size, diff --git a/xs_time.h b/xs_time.h index ce44cdc..979bde4 100644 --- a/xs_time.h +++ b/xs_time.h @@ -46,6 +46,7 @@ time_t xs_parse_time(const char *str, const char *fmt, int local) memset(&tm, '\0', sizeof(tm)); strptime(str, fmt, &tm); + /* try to guess the Daylight Saving Time */ if (local) tm.tm_isdst = -1;