summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2022-10-04 18:46:12 +0200
committerGravatar default2022-10-04 18:46:12 +0200
commitae06064e4d77d10b82c6061427dcc01d942b1dd8 (patch)
tree6da9cbb635f377f908e2a442cb122dc6a8f42b8a
parentFixed bug in the entry children popup. (diff)
downloadsnac2-ae06064e4d77d10b82c6061427dcc01d942b1dd8.tar.gz
snac2-ae06064e4d77d10b82c6061427dcc01d942b1dd8.tar.xz
snac2-ae06064e4d77d10b82c6061427dcc01d942b1dd8.zip
New command-line option purge.
-rw-r--r--data.c33
-rw-r--r--main.c18
-rw-r--r--snac.h2
-rw-r--r--xs_time.h1
4 files changed, 53 insertions, 1 deletions
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)
996 996
997 return obj; 997 return obj;
998} 998}
999
1000
1001void 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}
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)
18 printf("init [{basedir}] Initializes the database\n"); 18 printf("init [{basedir}] Initializes the database\n");
19 printf("adduser {basedir} [{uid}] Adds a new user\n"); 19 printf("adduser {basedir} [{uid}] Adds a new user\n");
20 printf("httpd {basedir} Starts the HTTPD daemon\n"); 20 printf("httpd {basedir} Starts the HTTPD daemon\n");
21 printf("purge {basedir} Purges old data\n");
21 printf("webfinger {basedir} {user} Queries about a @user@host or actor\n"); 22 printf("webfinger {basedir} {user} Queries about a @user@host or actor\n");
22 printf("queue {basedir} {uid} Processes a user queue\n"); 23 printf("queue {basedir} {uid} Processes a user queue\n");
23 printf("follow {basedir} {uid} {actor} Follows an actor\n"); 24 printf("follow {basedir} {uid} {actor} Follows an actor\n");
24 25
25// printf("check {basedir} [{uid}] Checks the database\n"); 26// printf("check {basedir} [{uid}] Checks the database\n");
26// printf("purge {basedir} [{uid}] Purges old data\n");
27 27
28// printf("update {basedir} {uid} Sends a user update to followers\n"); 28// printf("update {basedir} {uid} Sends a user update to followers\n");
29// printf("passwd {basedir} {uid} Sets the password for {uid}\n"); 29// printf("passwd {basedir} {uid} Sets the password for {uid}\n");
@@ -95,6 +95,22 @@ int main(int argc, char *argv[])
95 return 0; 95 return 0;
96 } 96 }
97 97
98 if (strcmp(cmd, "purge") == 0) {
99 /* iterate all users */
100 xs *list = user_list();
101 char *p, *uid;
102
103 p = list;
104 while (xs_list_iter(&p, &uid)) {
105 if (user_open(&snac, uid)) {
106 purge(&snac);
107 user_free(&snac);
108 }
109 }
110
111 return 0;
112 }
113
98 if ((user = GET_ARGV()) == NULL) 114 if ((user = GET_ARGV()) == NULL)
99 return usage(); 115 return usage();
100 116
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);
94d_char *queue(snac *snac); 94d_char *queue(snac *snac);
95d_char *dequeue(snac *snac, char *fn); 95d_char *dequeue(snac *snac, char *fn);
96 96
97void purge(snac *snac);
98
97d_char *http_signed_request(snac *snac, char *method, char *url, 99d_char *http_signed_request(snac *snac, char *method, char *url,
98 d_char *headers, 100 d_char *headers,
99 d_char *body, int b_size, 101 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)
46 memset(&tm, '\0', sizeof(tm)); 46 memset(&tm, '\0', sizeof(tm));
47 strptime(str, fmt, &tm); 47 strptime(str, fmt, &tm);
48 48
49 /* try to guess the Daylight Saving Time */
49 if (local) 50 if (local)
50 tm.tm_isdst = -1; 51 tm.tm_isdst = -1;
51 52