summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'data.c')
-rw-r--r--data.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/data.c b/data.c
index b36e31e..4ec5642 100644
--- a/data.c
+++ b/data.c
@@ -4362,3 +4362,61 @@ const char *lang_str(const char *str, const snac *user)
4362 4362
4363 return n_str; 4363 return n_str;
4364} 4364}
4365
4366
4367/** integrity checks **/
4368
4369void data_fsck(void)
4370{
4371 xs *list = user_list();
4372 const char *uid;
4373
4374 xs_list_foreach(list, uid) {
4375 snac user;
4376
4377 if (!user_open(&user, uid))
4378 continue;
4379
4380 {
4381 /* iterate all private posts and check that non-public posts
4382 from this user are also linked into the public directory,
4383 to avoid the don't-fucking-delete-my-own-private-posts purge bug */
4384
4385 xs *priv_spec = xs_fmt("%s/private/""*.json", user.basedir);
4386 xs *posts = xs_glob(priv_spec, 0, 0);
4387 const char *priv_fn;
4388
4389 xs_list_foreach(posts, priv_fn) {
4390 xs *pub_fn = xs_replace(priv_fn, "/private/", "/public/");
4391
4392 /* already there? look no more */
4393 if (mtime(pub_fn))
4394 continue;
4395
4396 /* read the post */
4397 FILE *f;
4398 if ((f = fopen(priv_fn, "r")) == NULL)
4399 continue;
4400
4401 xs *post = xs_json_load(f);
4402 fclose(f);
4403
4404 if (!xs_is_dict(post))
4405 continue;
4406
4407 const char *attr_to = get_atto(post);
4408
4409 if (!xs_is_string(attr_to) || strcmp(attr_to, user.actor) != 0) {
4410 /* not from this user */
4411 continue;
4412 }
4413
4414 /* link */
4415 snac_log(&user, xs_fmt("fsck: fixed missing link %s", xs_dict_get(post, "id")));
4416 link(priv_fn, pub_fn);
4417 }
4418 }
4419
4420 user_free(&user);
4421 }
4422}