summaryrefslogtreecommitdiff
path: root/apps/tagcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tagcache.c')
-rw-r--r--apps/tagcache.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 1a47b10ba8..1e05b7c902 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -489,14 +489,23 @@ static bool build_lookup_list(struct tagcache_search *tcs)
489 /* Check for conditions. */ 489 /* Check for conditions. */
490 for (i = 0; i < tcs->clause_count; i++) 490 for (i = 0; i < tcs->clause_count; i++)
491 { 491 {
492 struct tagfile_entry tfe;
492 int seek = entry.tag_seek[tcs->clause[i]->tag]; 493 int seek = entry.tag_seek[tcs->clause[i]->tag];
493 char str[64]; 494 char str[64];
494 495
495 memset(str, 0, sizeof str); 496 memset(str, 0, sizeof str);
496 if (!tagcache_is_numeric_tag(tcs->clause[i]->tag)) 497 if (!tagcache_is_numeric_tag(tcs->clause[i]->tag))
497 { 498 {
498 /* FIXME: Not yet implemented. */ 499 int fd = tcs->idxfd[tcs->clause[i]->tag];
499 // str = &hdr->tags[tcs->clause[i].tag][seek]; 500 lseek(fd, seek, SEEK_SET);
501 read(fd, &tfe, sizeof(struct tagfile_entry));
502 if (tfe.tag_length >= (int)sizeof(str))
503 {
504 logf("Too long tag read!");
505 break ;
506 }
507
508 read(fd, str, tfe.tag_length);
500 } 509 }
501 510
502 if (!check_against_clause(seek, str, tcs->clause[i])) 511 if (!check_against_clause(seek, str, tcs->clause[i]))
@@ -531,6 +540,7 @@ bool tagcache_search(struct tagcache_search *tcs, int tag)
531{ 540{
532 struct tagcache_header h; 541 struct tagcache_header h;
533 char buf[MAX_PATH]; 542 char buf[MAX_PATH];
543 int i;
534 544
535 if (tcs->valid) 545 if (tcs->valid)
536 tagcache_search_finish(tcs); 546 tagcache_search_finish(tcs);
@@ -545,6 +555,9 @@ bool tagcache_search(struct tagcache_search *tcs, int tag)
545 tcs->valid = true; 555 tcs->valid = true;
546 tcs->masterfd = -1; 556 tcs->masterfd = -1;
547 557
558 for (i = 0; i < TAG_COUNT; i++)
559 tcs->idxfd[i] = -1;
560
548#ifndef HAVE_TC_RAMCACHE 561#ifndef HAVE_TC_RAMCACHE
549 tcs->ramsearch = false; 562 tcs->ramsearch = false;
550#else 563#else
@@ -567,6 +580,8 @@ bool tagcache_search(struct tagcache_search *tcs, int tag)
567 return false; 580 return false;
568 } 581 }
569 582
583 tcs->idxfd[tcs->type] = tcs->fd;
584
570 /* Check the header. */ 585 /* Check the header. */
571 if (read(tcs->fd, &h, sizeof(struct tagcache_header)) != 586 if (read(tcs->fd, &h, sizeof(struct tagcache_header)) !=
572 sizeof(struct tagcache_header) || h.magic != TAGCACHE_MAGIC) 587 sizeof(struct tagcache_header) || h.magic != TAGCACHE_MAGIC)
@@ -617,6 +632,14 @@ bool tagcache_search_add_clause(struct tagcache_search *tcs,
617 logf("Too many clauses"); 632 logf("Too many clauses");
618 return false; 633 return false;
619 } 634 }
635
636 if (!tagcache_is_numeric_tag(clause->tag) && tcs->idxfd[clause->tag] < 0)
637 {
638 char buf[MAX_PATH];
639
640 snprintf(buf, sizeof buf, TAGCACHE_FILE_INDEX, clause->tag);
641 tcs->idxfd[clause->tag] = open(buf, O_RDONLY);
642 }
620 643
621 tcs->clause[tcs->clause_count] = clause; 644 tcs->clause[tcs->clause_count] = clause;
622 tcs->clause_count++; 645 tcs->clause_count++;
@@ -753,10 +776,13 @@ void tagcache_modify(struct tagcache_search *tcs, int type, const char *text)
753 776
754void tagcache_search_finish(struct tagcache_search *tcs) 777void tagcache_search_finish(struct tagcache_search *tcs)
755{ 778{
779 int i;
780
756 if (tcs->fd >= 0) 781 if (tcs->fd >= 0)
757 { 782 {
758 close(tcs->fd); 783 close(tcs->fd);
759 tcs->fd = -1; 784 tcs->fd = -1;
785 tcs->idxfd[tcs->type] = -1;
760 } 786 }
761 787
762 if (tcs->masterfd >= 0) 788 if (tcs->masterfd >= 0)
@@ -764,6 +790,15 @@ void tagcache_search_finish(struct tagcache_search *tcs)
764 close(tcs->masterfd); 790 close(tcs->masterfd);
765 tcs->masterfd = -1; 791 tcs->masterfd = -1;
766 } 792 }
793
794 for (i = 0; i < TAG_COUNT; i++)
795 {
796 if (tcs->idxfd[i] >= 0)
797 {
798 close(tcs->idxfd[i]);
799 tcs->idxfd[i] = -1;
800 }
801 }
767 802
768 tcs->ramsearch = false; 803 tcs->ramsearch = false;
769 tcs->valid = false; 804 tcs->valid = false;