diff options
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 62 |
1 files changed, 62 insertions, 0 deletions
| @@ -328,6 +328,51 @@ int index_add(const char *fn, const char *id) | |||
| 328 | } | 328 | } |
| 329 | 329 | ||
| 330 | 330 | ||
| 331 | int 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 | |||
| 368 | int 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 | |||
| 331 | int index_gc(const char *fn) | 376 | int 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 | ||
| 820 | int 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 | |||
| 775 | int _object_user_cache(snac *snac, const char *id, const char *cachedir, int del) | 837 | int _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 | { |