diff options
Diffstat (limited to 'apps/tagcache.c')
-rw-r--r-- | apps/tagcache.c | 121 |
1 files changed, 119 insertions, 2 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c index a5675850bf..47d9c4ed80 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -478,6 +478,7 @@ static bool build_lookup_list(struct tagcache_search *tcs) | |||
478 | { | 478 | { |
479 | struct index_entry *idx = &hdr->indices[i]; | 479 | struct index_entry *idx = &hdr->indices[i]; |
480 | int seek; | 480 | int seek; |
481 | char buf[256]; | ||
481 | char *str = NULL; | 482 | char *str = NULL; |
482 | struct tagfile_entry *entry; | 483 | struct tagfile_entry *entry; |
483 | 484 | ||
@@ -485,8 +486,16 @@ static bool build_lookup_list(struct tagcache_search *tcs) | |||
485 | 486 | ||
486 | if (!tagcache_is_numeric_tag(tcs->clause[j]->tag)) | 487 | if (!tagcache_is_numeric_tag(tcs->clause[j]->tag)) |
487 | { | 488 | { |
488 | entry = (struct tagfile_entry *)&hdr->tags[tcs->clause[j]->tag][seek]; | 489 | if (tcs->clause[j]->tag == tag_filename) |
489 | str = entry->tag_data; | 490 | { |
491 | tagcache_retrieve(tcs, i, buf, sizeof buf); | ||
492 | str = buf; | ||
493 | } | ||
494 | else | ||
495 | { | ||
496 | entry = (struct tagfile_entry *)&hdr->tags[tcs->clause[j]->tag][seek]; | ||
497 | str = entry->tag_data; | ||
498 | } | ||
490 | } | 499 | } |
491 | 500 | ||
492 | 501 | ||
@@ -2104,6 +2113,114 @@ static int open_master_fd(struct tagcache_header *hdr) | |||
2104 | return fd; | 2113 | return fd; |
2105 | } | 2114 | } |
2106 | 2115 | ||
2116 | static bool write_tag(int fd, const char *tagstr, const char *datastr) | ||
2117 | { | ||
2118 | char buf[256]; | ||
2119 | int i; | ||
2120 | |||
2121 | snprintf(buf, sizeof buf, "%s=\"", tagstr); | ||
2122 | for (i = strlen(buf); i < (long)sizeof(buf)-2; i++) | ||
2123 | { | ||
2124 | if (*datastr == '\0') | ||
2125 | break; | ||
2126 | |||
2127 | if (*datastr == '"') | ||
2128 | { | ||
2129 | buf[i] = '\\'; | ||
2130 | *datastr++; | ||
2131 | continue; | ||
2132 | } | ||
2133 | |||
2134 | buf[i] = *(datastr++); | ||
2135 | } | ||
2136 | |||
2137 | strcpy(&buf[i], "\" "); | ||
2138 | |||
2139 | write(fd, buf, i + 2); | ||
2140 | |||
2141 | return true; | ||
2142 | } | ||
2143 | |||
2144 | bool tagcache_create_changelog(struct tagcache_search *tcs) | ||
2145 | { | ||
2146 | static const char *tags_str[] = { "artist", "album", "genre", "title", | ||
2147 | "filename", "playcount", "playtime", "lastplayed" }; | ||
2148 | static const int tags[] = { tag_artist, tag_album, tag_genre, tag_title, | ||
2149 | tag_filename, tag_playcount, tag_playtime, tag_lastplayed }; | ||
2150 | struct tagcache_header myhdr; | ||
2151 | struct index_entry idx; | ||
2152 | char buf[256]; | ||
2153 | char temp[32]; | ||
2154 | int clfd; | ||
2155 | int i, j; | ||
2156 | |||
2157 | if (!tagcache_search(tcs, tag_filename)) | ||
2158 | return false; | ||
2159 | |||
2160 | /* Initialize the changelog */ | ||
2161 | clfd = open(TAGCACHE_FILE_CHANGELOG, O_WRONLY | O_CREAT | O_TRUNC); | ||
2162 | if (clfd < 0) | ||
2163 | { | ||
2164 | logf("failure to open changelog"); | ||
2165 | return false; | ||
2166 | } | ||
2167 | |||
2168 | if (tcs->masterfd < 0) | ||
2169 | { | ||
2170 | if ( (tcs->masterfd = open_master_fd(&myhdr)) < 0) | ||
2171 | return false; | ||
2172 | } | ||
2173 | else | ||
2174 | { | ||
2175 | lseek(tcs->masterfd, 0, SEEK_SET); | ||
2176 | read(tcs->masterfd, &myhdr, sizeof(struct tagcache_header)); | ||
2177 | } | ||
2178 | |||
2179 | write(clfd, "## Changelog version 1\n", 23); | ||
2180 | |||
2181 | for (i = 0; i < myhdr.entry_count; i++) | ||
2182 | { | ||
2183 | if (read(tcs->masterfd, &idx, sizeof(struct index_entry)) | ||
2184 | != sizeof(struct index_entry)) | ||
2185 | { | ||
2186 | logf("read error"); | ||
2187 | tagcache_search_finish(tcs); | ||
2188 | close(clfd); | ||
2189 | return false; | ||
2190 | } | ||
2191 | |||
2192 | /* Skip until the entry found has been modified. */ | ||
2193 | if (! (idx.flag & FLAG_DIRTYNUM) ) | ||
2194 | continue; | ||
2195 | |||
2196 | logf("Found!"); | ||
2197 | |||
2198 | /* Now retrieve all tags. */ | ||
2199 | for (j = 0; j < (long)(sizeof(tags) / sizeof(tags[0])); j++) | ||
2200 | { | ||
2201 | if (tagcache_is_numeric_tag(tags[j])) | ||
2202 | { | ||
2203 | snprintf(temp, sizeof temp, "%d", idx.tag_seek[tags[j]]); | ||
2204 | write_tag(clfd, tags_str[j], temp); | ||
2205 | continue; | ||
2206 | } | ||
2207 | |||
2208 | tcs->type = tags[j]; | ||
2209 | tagcache_retrieve(tcs, i, buf, sizeof buf); | ||
2210 | logf("tag: %s", buf); | ||
2211 | write_tag(clfd, tags_str[j], buf); | ||
2212 | } | ||
2213 | |||
2214 | write(clfd, "\n", 1); | ||
2215 | } | ||
2216 | |||
2217 | close(clfd); | ||
2218 | |||
2219 | tagcache_search_finish(tcs); | ||
2220 | |||
2221 | return true; | ||
2222 | } | ||
2223 | |||
2107 | bool tagcache_modify_numeric_entry(struct tagcache_search *tcs, | 2224 | bool tagcache_modify_numeric_entry(struct tagcache_search *tcs, |
2108 | int tag, long data) | 2225 | int tag, long data) |
2109 | { | 2226 | { |