summaryrefslogtreecommitdiff
path: root/apps/tagcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tagcache.c')
-rw-r--r--apps/tagcache.c83
1 files changed, 46 insertions, 37 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index b12d1de7f6..40f9c28c33 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -92,6 +92,9 @@
92#include "lang.h" 92#include "lang.h"
93#include "eeprom_settings.h" 93#include "eeprom_settings.h"
94#endif 94#endif
95#define USR_CANCEL false
96#else/*!defined(PLUGIN)*/
97#define USR_CANCEL (tc_stat.commit_delayed == true)
95#endif /*!defined(PLUGIN)*/ 98#endif /*!defined(PLUGIN)*/
96/* 99/*
97 * Define this to support non-native endian tagcache files. 100 * Define this to support non-native endian tagcache files.
@@ -2370,7 +2373,7 @@ static bool tempbuf_insert(char *str, int id, int idx_id, bool unique)
2370 unsigned *crcbuf = (unsigned *)&tempbuf[tempbuf_size-4]; 2373 unsigned *crcbuf = (unsigned *)&tempbuf[tempbuf_size-4];
2371 unsigned crc32 = 0xffffffff; 2374 unsigned crc32 = 0xffffffff;
2372 char chr_lower; 2375 char chr_lower;
2373 for (i = 0; str[i] != '\0' && i < len; i++) 2376 for (i = 0; str[i] != '\0' && i < len -1; i++)
2374 { 2377 {
2375 chr_lower = tolower(str[i]); 2378 chr_lower = tolower(str[i]);
2376 crc32 = crc_32(&chr_lower, 1, crc32); 2379 crc32 = crc_32(&chr_lower, 1, crc32);
@@ -2404,9 +2407,12 @@ static bool tempbuf_insert(char *str, int id, int idx_id, bool unique)
2404 2407
2405 /* Insert it to the buffer. */ 2408 /* Insert it to the buffer. */
2406 tempbuf_left -= len; 2409 tempbuf_left -= len;
2407 if (tempbuf_left - 4 < 0 || tempbufidx >= commit_entry_count-1) 2410 if (tempbuf_left - 4 < 0 || tempbufidx >= commit_entry_count)
2411 {
2412 logf("temp buf error rem: %ld idx: %d / %d",
2413 tempbuf_left, tempbufidx, commit_entry_count-1);
2408 return false; 2414 return false;
2409 2415 }
2410 if (id >= lookup_buffer_depth) 2416 if (id >= lookup_buffer_depth)
2411 { 2417 {
2412 logf("lookup buf overf. #2: %d", id); 2418 logf("lookup buf overf. #2: %d", id);
@@ -2585,7 +2591,7 @@ static bool build_numeric_indices(struct tagcache_header *h, int tmpfd)
2585 return false; 2591 return false;
2586 } 2592 }
2587 2593
2588 while (entries_processed < h->entry_count) 2594 while (entries_processed < h->entry_count && !USR_CANCEL)
2589 { 2595 {
2590 int count = MIN(h->entry_count - entries_processed, max_entries); 2596 int count = MIN(h->entry_count - entries_processed, max_entries);
2591 2597
@@ -2651,7 +2657,7 @@ static bool build_numeric_indices(struct tagcache_header *h, int tmpfd)
2651 lseek(masterfd, sizeof(struct master_header), SEEK_SET); 2657 lseek(masterfd, sizeof(struct master_header), SEEK_SET);
2652 2658
2653 /* Check if we can resurrect some deleted runtime statistics data. */ 2659 /* Check if we can resurrect some deleted runtime statistics data. */
2654 for (i = 0; i < tcmh.tch.entry_count; i++) 2660 for (i = 0; i < tcmh.tch.entry_count && !USR_CANCEL; i++)
2655 { 2661 {
2656 /* Read the index entry. */ 2662 /* Read the index entry. */
2657 if (read_index_entries(masterfd, &idx, 1) != sizeof(struct index_entry)) 2663 if (read_index_entries(masterfd, &idx, 1) != sizeof(struct index_entry))
@@ -2742,7 +2748,7 @@ static bool build_numeric_indices(struct tagcache_header *h, int tmpfd)
2742 lseek(masterfd, masterfd_pos, SEEK_SET); 2748 lseek(masterfd, masterfd_pos, SEEK_SET);
2743 2749
2744 /* Commit the data to the index. */ 2750 /* Commit the data to the index. */
2745 for (i = 0; i < count; i++) 2751 for (i = 0; i < count && !USR_CANCEL; i++)
2746 { 2752 {
2747 int loc = lseek(masterfd, 0, SEEK_CUR); 2753 int loc = lseek(masterfd, 0, SEEK_CUR);
2748 2754
@@ -2895,7 +2901,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
2895 if (TAGCACHE_IS_SORTED(index_type)) 2901 if (TAGCACHE_IS_SORTED(index_type))
2896 { 2902 {
2897 logf("loading tags..."); 2903 logf("loading tags...");
2898 for (i = 0; i < tch.entry_count; i++) 2904 for (i = 0; i < tch.entry_count && !USR_CANCEL; i++)
2899 { 2905 {
2900 struct tagfile_entry entry; 2906 struct tagfile_entry entry;
2901 int loc = lseek(fd, 0, SEEK_CUR); 2907 int loc = lseek(fd, 0, SEEK_CUR);
@@ -3040,7 +3046,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
3040 lseek(tmpfd, sizeof(struct tagcache_header), SEEK_SET); 3046 lseek(tmpfd, sizeof(struct tagcache_header), SEEK_SET);
3041 /* h is the header of the temporary file containing new tags. */ 3047 /* h is the header of the temporary file containing new tags. */
3042 logf("inserting new tags..."); 3048 logf("inserting new tags...");
3043 for (i = 0; i < h->entry_count; i++) 3049 for (i = 0; i < h->entry_count && !USR_CANCEL; i++)
3044 { 3050 {
3045 struct temp_file_entry entry; 3051 struct temp_file_entry entry;
3046 3052
@@ -3112,7 +3118,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
3112 */ 3118 */
3113 logf("updating indices..."); 3119 logf("updating indices...");
3114 lseek(masterfd, sizeof(struct master_header), SEEK_SET); 3120 lseek(masterfd, sizeof(struct master_header), SEEK_SET);
3115 for (i = 0; i < tcmh.tch.entry_count; i += idxbuf_pos) 3121 for (i = 0; i < tcmh.tch.entry_count && !USR_CANCEL; i += idxbuf_pos)
3116 { 3122 {
3117 int j; 3123 int j;
3118 int loc = lseek(masterfd, 0, SEEK_CUR); 3124 int loc = lseek(masterfd, 0, SEEK_CUR);
@@ -3172,7 +3178,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
3172 lseek(masterfd, masterfd_pos, SEEK_SET); 3178 lseek(masterfd, masterfd_pos, SEEK_SET);
3173 lseek(tmpfd, sizeof(struct tagcache_header), SEEK_SET); 3179 lseek(tmpfd, sizeof(struct tagcache_header), SEEK_SET);
3174 lseek(fd, 0, SEEK_END); 3180 lseek(fd, 0, SEEK_END);
3175 for (i = 0; i < h->entry_count; i += idxbuf_pos) 3181 for (i = 0; i < h->entry_count && !USR_CANCEL; i += idxbuf_pos)
3176 { 3182 {
3177 int j; 3183 int j;
3178 3184
@@ -3412,7 +3418,7 @@ static bool commit(void)
3412 tch.datasize = 0; 3418 tch.datasize = 0;
3413 tc_stat.commit_delayed = false; 3419 tc_stat.commit_delayed = false;
3414 3420
3415 for (i = 0; i < TAG_COUNT; i++) 3421 for (i = 0; i < TAG_COUNT && !USR_CANCEL; i++)
3416 { 3422 {
3417 int ret; 3423 int ret;
3418 3424
@@ -3446,41 +3452,44 @@ static bool commit(void)
3446 3452
3447 tc_stat.commit_step = 0; 3453 tc_stat.commit_step = 0;
3448 3454
3449 /* Update the master index headers. */ 3455 if (!USR_CANCEL)
3450 if ( (masterfd = open_master_fd(&tcmh, true)) < 0) 3456 {
3451 goto commit_error; 3457 /* Update the master index headers. */
3458 if ( (masterfd = open_master_fd(&tcmh, true)) < 0)
3459 goto commit_error;
3452 3460
3453 remove_db_file(TAGCACHE_FILE_TEMP); 3461 remove_db_file(TAGCACHE_FILE_TEMP);
3454 3462
3455 tcmh.tch.entry_count += tch.entry_count; 3463 tcmh.tch.entry_count += tch.entry_count;
3456 tcmh.tch.datasize = sizeof(struct master_header) 3464 tcmh.tch.datasize = sizeof(struct master_header)
3457 + sizeof(struct index_entry) * tcmh.tch.entry_count 3465 + sizeof(struct index_entry) * tcmh.tch.entry_count
3458 + tch.datasize; 3466 + tch.datasize;
3459 tcmh.dirty = false; 3467 tcmh.dirty = false;
3460 tcmh.commitid++; 3468 tcmh.commitid++;
3461 3469
3462 lseek(masterfd, 0, SEEK_SET); 3470 lseek(masterfd, 0, SEEK_SET);
3463 write_master_header(masterfd, &tcmh); 3471 write_master_header(masterfd, &tcmh);
3464 close(masterfd); 3472 close(masterfd);
3465 3473
3466 logf("tagcache committed"); 3474 logf("tagcache committed");
3467 tagcache_commit_finalize(); 3475 tagcache_commit_finalize();
3468 3476
3469#if defined(HAVE_TC_RAMCACHE) 3477#if defined(HAVE_TC_RAMCACHE)
3470 if (ramcache_buffer_stolen) 3478 if (ramcache_buffer_stolen)
3471 { 3479 {
3472 tempbuf = NULL; 3480 tempbuf = NULL;
3473 tempbuf_size = 0; 3481 tempbuf_size = 0;
3474 ramcache_buffer_stolen = false; 3482 ramcache_buffer_stolen = false;
3475 tcrc_buffer_unlock(); 3483 tcrc_buffer_unlock();
3476 } 3484 }
3477 3485
3478 /* Reload tagcache. */ 3486 /* Reload tagcache. */
3479 if (tc_stat.ramcache_allocated > 0) 3487 if (tc_stat.ramcache_allocated > 0)
3480 tagcache_start_scan(); 3488 tagcache_start_scan();
3481#endif /* HAVE_TC_RAMCACHE */ 3489#endif /* HAVE_TC_RAMCACHE */
3482 3490
3483 rc = true; 3491 rc = true;
3492 } /*!USR_CANCEL*/
3484 3493
3485commit_error: 3494commit_error:
3486#ifdef HAVE_TC_RAMCACHE 3495#ifdef HAVE_TC_RAMCACHE