mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-14 17:45:04 +00:00
New command-line option purge.
This commit is contained in:
parent
5192e28444
commit
ae06064e4d
4 changed files with 53 additions and 1 deletions
33
data.c
33
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
18
main.c
18
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();
|
||||
|
||||
|
|
2
snac.h
2
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,
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue