summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/tagcache.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 0c8a6aaa1d..3e1647018c 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -49,8 +49,9 @@ static long tempbuf_size; /* Buffer size (TEMPBUF_SIZE). */
49static long tempbuf_left; /* Buffer space left. */ 49static long tempbuf_left; /* Buffer space left. */
50static long tempbuf_pos; 50static long tempbuf_pos;
51 51
52/* Tags we want to be unique (loaded to the tempbuf). */ 52/* Tags we want to get sorted (loaded to the tempbuf). */
53static const int unique_tags[] = { tag_artist, tag_album, tag_genre, tag_title }; 53static const int sorted_tags[] = { tag_artist, tag_album, tag_genre, tag_title };
54static const int unique_tags[] = { tag_artist, tag_album, tag_genre };
54 55
55/* Queue commands. */ 56/* Queue commands. */
56#define Q_STOP_SCAN 0 57#define Q_STOP_SCAN 0
@@ -63,7 +64,7 @@ static const int unique_tags[] = { tag_artist, tag_album, tag_genre, tag_title }
63#define TAGCACHE_FILE_INDEX ROCKBOX_DIR "/tagcache_%d.tcd" 64#define TAGCACHE_FILE_INDEX ROCKBOX_DIR "/tagcache_%d.tcd"
64 65
65/* Tag database structures. */ 66/* Tag database structures. */
66#define TAGCACHE_MAGIC 0x01020316 67#define TAGCACHE_MAGIC 0x01020317
67 68
68/* Variable-length tag entry in tag files. */ 69/* Variable-length tag entry in tag files. */
69struct tagfile_entry { 70struct tagfile_entry {
@@ -906,6 +907,19 @@ static bool is_unique_tag(int type)
906 return false; 907 return false;
907} 908}
908 909
910static bool is_sorted_tag(int type)
911{
912 int i;
913
914 for (i = 0; i < (int)(sizeof(sorted_tags)/sizeof(sorted_tags[0])); i++)
915 {
916 if (type == sorted_tags[i])
917 return true;
918 }
919
920 return false;
921}
922
909static bool build_index(int index_type, struct tagcache_header *h, int tmpfd) 923static bool build_index(int index_type, struct tagcache_header *h, int tmpfd)
910{ 924{
911 int i; 925 int i;
@@ -948,7 +962,7 @@ static bool build_index(int index_type, struct tagcache_header *h, int tmpfd)
948 * it entirely into memory so we can resort it later for use with 962 * it entirely into memory so we can resort it later for use with
949 * chunked browsing. 963 * chunked browsing.
950 */ 964 */
951 if (is_unique_tag(index_type)) 965 if (is_sorted_tag(index_type))
952 { 966 {
953 for (i = 0; i < tch.entry_count; i++) 967 for (i = 0; i < tch.entry_count; i++)
954 { 968 {
@@ -1075,7 +1089,7 @@ static bool build_index(int index_type, struct tagcache_header *h, int tmpfd)
1075 * Load new unique tags in memory to be sorted later and added 1089 * Load new unique tags in memory to be sorted later and added
1076 * to the master lookup file. 1090 * to the master lookup file.
1077 */ 1091 */
1078 if (is_unique_tag(index_type)) 1092 if (is_sorted_tag(index_type))
1079 { 1093 {
1080 lseek(tmpfd, sizeof(struct tagcache_header), SEEK_SET); 1094 lseek(tmpfd, sizeof(struct tagcache_header), SEEK_SET);
1081 /* h is the header of the temporary file containing new tags. */ 1095 /* h is the header of the temporary file containing new tags. */
@@ -1107,11 +1121,15 @@ static bool build_index(int index_type, struct tagcache_header *h, int tmpfd)
1107 error = true; 1121 error = true;
1108 goto error_exit; 1122 goto error_exit;
1109 } 1123 }
1110 1124
1111 if (!tempbuf_unique_insert(buf, i)) 1125 if (is_unique_tag(index_type))
1126 error = !tempbuf_unique_insert(buf, i);
1127 else
1128 error = !tempbuf_insert(buf, i);
1129
1130 if (error)
1112 { 1131 {
1113 logf("insert error"); 1132 logf("insert error");
1114 error = true;
1115 goto error_exit; 1133 goto error_exit;
1116 } 1134 }
1117 1135
@@ -1189,7 +1207,7 @@ static bool build_index(int index_type, struct tagcache_header *h, int tmpfd)
1189 } 1207 }
1190 1208
1191 /* Read entry headers. */ 1209 /* Read entry headers. */
1192 if (!is_unique_tag(index_type)) 1210 if (!is_sorted_tag(index_type))
1193 { 1211 {
1194 struct temp_file_entry entry; 1212 struct temp_file_entry entry;
1195 struct tagfile_entry fe; 1213 struct tagfile_entry fe;
@@ -1259,7 +1277,7 @@ static bool build_index(int index_type, struct tagcache_header *h, int tmpfd)
1259 } 1277 }
1260 1278
1261 /* Finally write the uniqued tag index file. */ 1279 /* Finally write the uniqued tag index file. */
1262 if (is_unique_tag(index_type)) 1280 if (is_sorted_tag(index_type))
1263 { 1281 {
1264 tch.magic = TAGCACHE_MAGIC; 1282 tch.magic = TAGCACHE_MAGIC;
1265 tch.entry_count = tempbufidx; 1283 tch.entry_count = tempbufidx;