diff options
Diffstat (limited to 'apps/tagcache.c')
-rw-r--r-- | apps/tagcache.c | 77 |
1 files changed, 40 insertions, 37 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c index 60d82d002b..0e07c4804b 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -930,9 +930,17 @@ static bool open_files(struct tagcache_search *tcs, int tag) | |||
930 | static bool retrieve(struct tagcache_search *tcs, IF_DIRCACHE(int idx_id,) | 930 | static bool retrieve(struct tagcache_search *tcs, IF_DIRCACHE(int idx_id,) |
931 | struct index_entry *idx, int tag, char *buf, long bufsz) | 931 | struct index_entry *idx, int tag, char *buf, long bufsz) |
932 | { | 932 | { |
933 | bool success = false; | ||
934 | bool is_basename = false; | ||
933 | struct tagfile_entry tfe; | 935 | struct tagfile_entry tfe; |
934 | long seek; | 936 | long seek; |
935 | 937 | ||
938 | if (tag == tag_virt_basename) | ||
939 | { | ||
940 | tag = tag_filename; | ||
941 | is_basename = true; | ||
942 | } | ||
943 | |||
936 | if (TAGCACHE_IS_NUMERIC(tag)) | 944 | if (TAGCACHE_IS_NUMERIC(tag)) |
937 | goto failure; | 945 | goto failure; |
938 | 946 | ||
@@ -950,7 +958,7 @@ static bool retrieve(struct tagcache_search *tcs, IF_DIRCACHE(int idx_id,) | |||
950 | if (tag == tag_filename && (idx->flag & FLAG_DIRCACHE)) | 958 | if (tag == tag_filename && (idx->flag & FLAG_DIRCACHE)) |
951 | { | 959 | { |
952 | if (dircache_get_fileref_path(&tcrc_dcfrefs[idx_id], buf, bufsz) >= 0) | 960 | if (dircache_get_fileref_path(&tcrc_dcfrefs[idx_id], buf, bufsz) >= 0) |
953 | return true; | 961 | success = true; |
954 | } | 962 | } |
955 | else | 963 | else |
956 | #endif /* HAVE_DIRCACHE */ | 964 | #endif /* HAVE_DIRCACHE */ |
@@ -959,13 +967,12 @@ static bool retrieve(struct tagcache_search *tcs, IF_DIRCACHE(int idx_id,) | |||
959 | struct tagfile_entry *ep = | 967 | struct tagfile_entry *ep = |
960 | (struct tagfile_entry *)&tcramcache.hdr->tags[tag][seek]; | 968 | (struct tagfile_entry *)&tcramcache.hdr->tags[tag][seek]; |
961 | strmemccpy(buf, ep->tag_data, bufsz); | 969 | strmemccpy(buf, ep->tag_data, bufsz); |
962 | 970 | success = true; | |
963 | return true; | ||
964 | } | 971 | } |
965 | } | 972 | } |
966 | #endif /* HAVE_TC_RAMCACHE */ | 973 | #endif /* HAVE_TC_RAMCACHE */ |
967 | 974 | ||
968 | if (open_files(tcs, tag)) | 975 | if (!success && open_files(tcs, tag)) |
969 | { | 976 | { |
970 | lseek(tcs->idxfd[tag], seek, SEEK_SET); | 977 | lseek(tcs->idxfd[tag], seek, SEEK_SET); |
971 | switch (ecread_tagfile_entry_and_tag(tcs->idxfd[tag], &tfe, buf, bufsz)) | 978 | switch (ecread_tagfile_entry_and_tag(tcs->idxfd[tag], &tfe, buf, bufsz)) |
@@ -984,10 +991,22 @@ static bool retrieve(struct tagcache_search *tcs, IF_DIRCACHE(int idx_id,) | |||
984 | break; | 991 | break; |
985 | case e_SUCCESS_LEN_ZERO: | 992 | case e_SUCCESS_LEN_ZERO: |
986 | case e_SUCCESS: | 993 | case e_SUCCESS: |
987 | return true; | 994 | success = true; |
995 | break; | ||
988 | } | 996 | } |
989 | } | 997 | } |
990 | 998 | ||
999 | if (success) | ||
1000 | { | ||
1001 | if (is_basename) | ||
1002 | { | ||
1003 | char* basename = strrchr(buf, '/'); | ||
1004 | if (basename != NULL) | ||
1005 | memmove(buf, basename + 1, strlen(basename)); /* includes NULL */ | ||
1006 | } | ||
1007 | return true; | ||
1008 | } | ||
1009 | |||
991 | failure: | 1010 | failure: |
992 | str_setlen(buf, 0); | 1011 | str_setlen(buf, 0); |
993 | return false; | 1012 | return false; |
@@ -1284,7 +1303,7 @@ static bool check_clauses(struct tagcache_search *tcs, | |||
1284 | if (clause->tag == tag_filename | 1303 | if (clause->tag == tag_filename |
1285 | || clause->tag == tag_virt_basename) | 1304 | || clause->tag == tag_virt_basename) |
1286 | { | 1305 | { |
1287 | retrieve(tcs, IF_DIRCACHE(tcs->idx_id,) idx, tag_filename, | 1306 | retrieve(tcs, IF_DIRCACHE(tcs->idx_id,) idx, clause->tag, |
1288 | buf, bufsz); | 1307 | buf, bufsz); |
1289 | } | 1308 | } |
1290 | else | 1309 | else |
@@ -1316,7 +1335,13 @@ static bool check_clauses(struct tagcache_search *tcs, | |||
1316 | case e_SUCCESS_LEN_ZERO: /* Check if entry has been deleted. */ | 1335 | case e_SUCCESS_LEN_ZERO: /* Check if entry has been deleted. */ |
1317 | return false; | 1336 | return false; |
1318 | case e_SUCCESS: | 1337 | case e_SUCCESS: |
1319 | break; | 1338 | if (clause->tag == tag_virt_basename) |
1339 | { | ||
1340 | char *basename = strrchr(str, '/'); | ||
1341 | if (basename) | ||
1342 | str = basename + 1; | ||
1343 | } | ||
1344 | break; | ||
1320 | case e_ENTRY_SIZEMISMATCH: | 1345 | case e_ENTRY_SIZEMISMATCH: |
1321 | logf("read error #15"); | 1346 | logf("read error #15"); |
1322 | return false; | 1347 | return false; |
@@ -1333,13 +1358,6 @@ static bool check_clauses(struct tagcache_search *tcs, | |||
1333 | } | 1358 | } |
1334 | } | 1359 | } |
1335 | 1360 | ||
1336 | if (clause->tag == tag_virt_basename) | ||
1337 | { | ||
1338 | char *basename = strrchr(str, '/'); | ||
1339 | if (basename) | ||
1340 | str = basename + 1; | ||
1341 | } | ||
1342 | |||
1343 | if (!check_against_clause(seek, str, clause)) | 1361 | if (!check_against_clause(seek, str, clause)) |
1344 | { | 1362 | { |
1345 | /* Clause failed -- try finding a logical-or clause */ | 1363 | /* Clause failed -- try finding a logical-or clause */ |
@@ -1709,7 +1727,7 @@ bool tagcache_search_add_clause(struct tagcache_search *tcs, | |||
1709 | return true; | 1727 | return true; |
1710 | } | 1728 | } |
1711 | 1729 | ||
1712 | static bool get_next(struct tagcache_search *tcs) | 1730 | static bool get_next(struct tagcache_search *tcs, bool is_numeric) |
1713 | { | 1731 | { |
1714 | /* WARNING pointers into buf are used in outside functions */ | 1732 | /* WARNING pointers into buf are used in outside functions */ |
1715 | static char buf[TAGCACHE_BUFSZ]; | 1733 | static char buf[TAGCACHE_BUFSZ]; |
@@ -1719,11 +1737,6 @@ static bool get_next(struct tagcache_search *tcs) | |||
1719 | long flag = 0; | 1737 | long flag = 0; |
1720 | #endif | 1738 | #endif |
1721 | 1739 | ||
1722 | if (!tcs->valid || !tc_stat.ready) | ||
1723 | return false; | ||
1724 | |||
1725 | bool is_numeric = TAGCACHE_IS_NUMERIC(tcs->type); | ||
1726 | |||
1727 | if (tcs->idxfd[tcs->type] < 0 && !is_numeric | 1740 | if (tcs->idxfd[tcs->type] < 0 && !is_numeric |
1728 | #ifdef HAVE_TC_RAMCACHE | 1741 | #ifdef HAVE_TC_RAMCACHE |
1729 | && !tcs->ramsearch | 1742 | && !tcs->ramsearch |
@@ -1849,9 +1862,6 @@ static bool get_next(struct tagcache_search *tcs) | |||
1849 | tcs->valid = false; | 1862 | tcs->valid = false; |
1850 | logf("read error #4"); | 1863 | logf("read error #4"); |
1851 | return false; | 1864 | return false; |
1852 | default: | ||
1853 | logf("unknown_error"); | ||
1854 | break;; | ||
1855 | } | 1865 | } |
1856 | 1866 | ||
1857 | /** | 1867 | /** |
@@ -1871,12 +1881,15 @@ static bool get_next(struct tagcache_search *tcs) | |||
1871 | 1881 | ||
1872 | bool tagcache_get_next(struct tagcache_search *tcs) | 1882 | bool tagcache_get_next(struct tagcache_search *tcs) |
1873 | { | 1883 | { |
1874 | while (get_next(tcs)) | 1884 | if (tcs->valid && tagcache_is_usable()) |
1875 | { | 1885 | { |
1876 | if (tcs->result_len > 1) | 1886 | bool is_numeric = TAGCACHE_IS_NUMERIC(tcs->type); |
1877 | return true; | 1887 | while (get_next(tcs, is_numeric)) |
1888 | { | ||
1889 | if (tcs->result_len > 1) | ||
1890 | return true; | ||
1891 | } | ||
1878 | } | 1892 | } |
1879 | |||
1880 | #ifdef LOGF_ENABLE | 1893 | #ifdef LOGF_ENABLE |
1881 | if (tcs->unique_list_count > 0) | 1894 | if (tcs->unique_list_count > 0) |
1882 | logf(" uniqbuf: %d used / %d avail", tcs->unique_list_count, tcs->unique_list_capacity); | 1895 | logf(" uniqbuf: %d used / %d avail", tcs->unique_list_count, tcs->unique_list_capacity); |
@@ -2817,9 +2830,6 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd) | |||
2817 | logf("read error #8"); | 2830 | logf("read error #8"); |
2818 | close(fd); | 2831 | close(fd); |
2819 | return -2; | 2832 | return -2; |
2820 | default: | ||
2821 | logf("unknown_error"); | ||
2822 | break;; | ||
2823 | } | 2833 | } |
2824 | 2834 | ||
2825 | /** | 2835 | /** |
@@ -3994,9 +4004,6 @@ static bool delete_entry(long idx_id) | |||
3994 | case e_TAG_SIZEMISMATCH: | 4004 | case e_TAG_SIZEMISMATCH: |
3995 | logf("delete_entry(): read error #3"); | 4005 | logf("delete_entry(): read error #3"); |
3996 | goto cleanup; | 4006 | goto cleanup; |
3997 | default: | ||
3998 | logf("unknown_error"); | ||
3999 | break;; | ||
4000 | } | 4007 | } |
4001 | 4008 | ||
4002 | myidx.tag_seek[tag] = crc_32(buf, strlen(buf), 0xffffffff); | 4009 | myidx.tag_seek[tag] = crc_32(buf, strlen(buf), 0xffffffff); |
@@ -4519,10 +4526,6 @@ static bool check_file_refs(bool auto_update) | |||
4519 | 4526 | ||
4520 | switch (res) | 4527 | switch (res) |
4521 | { | 4528 | { |
4522 | default: | ||
4523 | logf("read error"); | ||
4524 | ret = false; | ||
4525 | goto wend_finished; | ||
4526 | case e_ENTRY_SIZEMISMATCH: | 4529 | case e_ENTRY_SIZEMISMATCH: |
4527 | logf("size mismatch entry EOF?"); /* likely EOF */ | 4530 | logf("size mismatch entry EOF?"); /* likely EOF */ |
4528 | ret = false; | 4531 | ret = false; |