diff options
| author | 2023-02-23 18:43:52 +0100 | |
|---|---|---|
| committer | 2023-02-23 18:43:52 +0100 | |
| commit | 163051906640bc401ae7aefa97c101c3696c9167 (patch) | |
| tree | 1a389a4c29f4bc742e418fbb8b53c13dd228eb37 /data.c | |
| parent | Call index_gc() on the user indexes. (diff) | |
| download | snac2-163051906640bc401ae7aefa97c101c3696c9167.tar.gz snac2-163051906640bc401ae7aefa97c101c3696c9167.tar.xz snac2-163051906640bc401ae7aefa97c101c3696c9167.zip | |
Deleted index_del_md5() and index_del().
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 54 |
1 files changed, 1 insertions, 53 deletions
| @@ -327,57 +327,6 @@ int index_gc(const char *fn) | |||
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | 329 | ||
| 330 | int index_del_md5(const char *fn, const char *md5) | ||
| 331 | /* deletes an md5 from an index */ | ||
| 332 | { | ||
| 333 | int status = 404; | ||
| 334 | FILE *i, *o; | ||
| 335 | |||
| 336 | pthread_mutex_lock(&data_mutex); | ||
| 337 | |||
| 338 | if ((i = fopen(fn, "r")) != NULL) { | ||
| 339 | flock(fileno(i), LOCK_EX); | ||
| 340 | |||
| 341 | xs *nfn = xs_fmt("%s.new", fn); | ||
| 342 | char line[256]; | ||
| 343 | |||
| 344 | if ((o = fopen(nfn, "w")) != NULL) { | ||
| 345 | while (fgets(line, sizeof(line), i) != NULL) { | ||
| 346 | line[32] = '\0'; | ||
| 347 | if (memcmp(line, md5, 32) != 0) | ||
| 348 | fprintf(o, "%s\n", line); | ||
| 349 | } | ||
| 350 | |||
| 351 | fclose(o); | ||
| 352 | |||
| 353 | xs *ofn = xs_fmt("%s.bak", fn); | ||
| 354 | |||
| 355 | unlink(ofn); | ||
| 356 | link(fn, ofn); | ||
| 357 | rename(nfn, fn); | ||
| 358 | } | ||
| 359 | else | ||
| 360 | status = 500; | ||
| 361 | |||
| 362 | fclose(i); | ||
| 363 | } | ||
| 364 | else | ||
| 365 | status = 500; | ||
| 366 | |||
| 367 | pthread_mutex_unlock(&data_mutex); | ||
| 368 | |||
| 369 | return status; | ||
| 370 | } | ||
| 371 | |||
| 372 | |||
| 373 | int index_del(const char *fn, const char *id) | ||
| 374 | /* deletes an id from an index */ | ||
| 375 | { | ||
| 376 | xs *md5 = xs_md5_hex(id, strlen(id)); | ||
| 377 | return index_del_md5(fn, md5); | ||
| 378 | } | ||
| 379 | |||
| 380 | |||
| 381 | int index_in_md5(const char *fn, const char *md5) | 330 | int index_in_md5(const char *fn, const char *md5) |
| 382 | /* checks if the md5 is already in the index */ | 331 | /* checks if the md5 is already in the index */ |
| 383 | { | 332 | { |
| @@ -779,8 +728,7 @@ int _object_user_cache(snac *snac, const char *id, const char *cachedir, int del | |||
| 779 | int ret; | 728 | int ret; |
| 780 | 729 | ||
| 781 | if (del) { | 730 | if (del) { |
| 782 | if ((ret = unlink(cfn)) != -1) | 731 | ret = unlink(cfn); |
| 783 | index_del(idx, id); | ||
| 784 | } | 732 | } |
| 785 | else { | 733 | else { |
| 786 | if ((ret = link(ofn, cfn)) != -1) | 734 | if ((ret = link(ofn, cfn)) != -1) |