summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-05-01 17:02:44 +0200
committerGravatar default2023-05-01 17:02:44 +0200
commitc21bbd5f7ca814d65a3759d429c1d673bee5081b (patch)
tree0bf28421b9ed629f6d44528dc137c09c9404229d
parentPurge / gc the instance timeline index. (diff)
downloadpenes-snac2-c21bbd5f7ca814d65a3759d429c1d673bee5081b.tar.gz
penes-snac2-c21bbd5f7ca814d65a3759d429c1d673bee5081b.tar.xz
penes-snac2-c21bbd5f7ca814d65a3759d429c1d673bee5081b.zip
New functions index_del_md5(), index_del() and object_unadmire().
-rw-r--r--data.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/data.c b/data.c
index 50d88eb..e038f81 100644
--- a/data.c
+++ b/data.c
@@ -328,6 +328,51 @@ int index_add(const char *fn, const char *id)
328} 328}
329 329
330 330
331int index_del_md5(const char *fn, const char *md5)
332/* deletes an md5 from an index */
333{
334 int status = 404;
335 FILE *f;
336
337 pthread_mutex_lock(&data_mutex);
338
339 if ((f = fopen(fn, "r+")) != NULL) {
340 char line[256];
341
342 while (fgets(line, sizeof(line), f) != NULL) {
343 line[32] = '\0';
344
345 if (strcmp(line, md5) == 0) {
346 /* found! just rewind, overwrite it with garbage
347 and an eventual call to index_gc() will clean it
348 [yes: this breaks index_len()] */
349 fseek(f, -33, SEEK_CUR);
350 fwrite("-", 1, 1, f);
351 status = 200;
352
353 break;
354 }
355 }
356
357 fclose(f);
358 }
359 else
360 status = 500;
361
362 pthread_mutex_unlock(&data_mutex);
363
364 return status;
365}
366
367
368int index_del(const char *fn, const char *id)
369/* deletes an id from an index */
370{
371 xs *md5 = xs_md5_hex(id, strlen(id));
372 return index_del_md5(fn, md5);
373}
374
375
331int index_gc(const char *fn) 376int index_gc(const char *fn)
332/* garbage-collects an index, deleting objects that are not here */ 377/* garbage-collects an index, deleting objects that are not here */
333{ 378{
@@ -772,6 +817,23 @@ int object_admire(const char *id, const char *actor, int like)
772} 817}
773 818
774 819
820int object_unadmire(const char *id, const char *actor, int like)
821/* actor no longer likes or announces this object */
822{
823 int status;
824 xs *fn = _object_fn(id);
825
826 fn = xs_replace_i(fn, ".json", like ? "_l.idx" : "_a.idx");
827
828 status = index_del(fn, actor);
829
830 srv_debug(1,
831 xs_fmt("object_unadmire (%s) %s %s %d", like ? "Like" : "Announce", actor, fn, status));
832
833 return status;
834}
835
836
775int _object_user_cache(snac *snac, const char *id, const char *cachedir, int del) 837int _object_user_cache(snac *snac, const char *id, const char *cachedir, int del)
776/* adds or deletes from a user cache */ 838/* adds or deletes from a user cache */
777{ 839{