summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'data.c')
-rw-r--r--data.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/data.c b/data.c
index b36e31e..1533305 100644
--- a/data.c
+++ b/data.c
@@ -3605,6 +3605,17 @@ void enqueue_collect_outbox(snac *user, const char *actor_id)
3605} 3605}
3606 3606
3607 3607
3608void enqueue_fsck(void)
3609/* enqueues an fsck */
3610{
3611 xs *qmsg = _new_qmsg("fsck", "", 0);
3612 const char *ntid = xs_dict_get(qmsg, "ntid");
3613 xs *fn = xs_fmt("%s/queue/%s.json", srv_basedir, ntid);
3614
3615 qmsg = _enqueue_put(fn, qmsg);
3616}
3617
3618
3608int was_question_voted(snac *user, const char *id) 3619int was_question_voted(snac *user, const char *id)
3609/* returns true if the user voted in this poll */ 3620/* returns true if the user voted in this poll */
3610{ 3621{
@@ -4362,3 +4373,61 @@ const char *lang_str(const char *str, const snac *user)
4362 4373
4363 return n_str; 4374 return n_str;
4364} 4375}
4376
4377
4378/** integrity checks **/
4379
4380void data_fsck(void)
4381{
4382 xs *list = user_list();
4383 const char *uid;
4384
4385 xs_list_foreach(list, uid) {
4386 snac user;
4387
4388 if (!user_open(&user, uid))
4389 continue;
4390
4391 {
4392 /* iterate all private posts and check that non-public posts
4393 from this user are also linked into the public directory,
4394 to avoid the don't-fucking-delete-my-own-private-posts purge bug */
4395
4396 xs *priv_spec = xs_fmt("%s/private/""*.json", user.basedir);
4397 xs *posts = xs_glob(priv_spec, 0, 0);
4398 const char *priv_fn;
4399
4400 xs_list_foreach(posts, priv_fn) {
4401 xs *pub_fn = xs_replace(priv_fn, "/private/", "/public/");
4402
4403 /* already there? look no more */
4404 if (mtime(pub_fn))
4405 continue;
4406
4407 /* read the post */
4408 FILE *f;
4409 if ((f = fopen(priv_fn, "r")) == NULL)
4410 continue;
4411
4412 xs *post = xs_json_load(f);
4413 fclose(f);
4414
4415 if (!xs_is_dict(post))
4416 continue;
4417
4418 const char *attr_to = get_atto(post);
4419
4420 if (!xs_is_string(attr_to) || strcmp(attr_to, user.actor) != 0) {
4421 /* not from this user */
4422 continue;
4423 }
4424
4425 /* link */
4426 snac_debug(&user, 1, xs_fmt("fsck: fixed missing link %s", xs_dict_get(post, "id")));
4427 link(priv_fn, pub_fn);
4428 }
4429 }
4430
4431 user_free(&user);
4432 }
4433}