summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/tagcache.c99
1 files changed, 58 insertions, 41 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 01dc09fdc8..ba7d8b9b64 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -72,6 +72,7 @@ static struct tagcache_stat stat;
72enum tagcache_queue { 72enum tagcache_queue {
73 Q_STOP_SCAN = 0, 73 Q_STOP_SCAN = 0,
74 Q_START_SCAN, 74 Q_START_SCAN,
75 Q_IMPORT_CHANGELOG,
75 Q_UPDATE, 76 Q_UPDATE,
76 Q_REBUILD, 77 Q_REBUILD,
77}; 78};
@@ -424,11 +425,10 @@ bool tagcache_find_index(struct tagcache_search *tcs, const char *filename)
424 return true; 425 return true;
425} 426}
426 427
427static bool tagcache_get_index(const struct tagcache_search *tcs, 428static bool get_index(int masterfd, int idxid, struct index_entry *idx)
428 int idxid, struct index_entry *idx)
429{ 429{
430#ifdef HAVE_TC_RAMCACHE 430#ifdef HAVE_TC_RAMCACHE
431 if (tcs->ramsearch) 431 if (stat.ramcache)
432 { 432 {
433 if (hdr->indices[idxid].flag & FLAG_DELETED) 433 if (hdr->indices[idxid].flag & FLAG_DELETED)
434 return false; 434 return false;
@@ -438,15 +438,37 @@ static bool tagcache_get_index(const struct tagcache_search *tcs,
438 } 438 }
439#endif 439#endif
440 440
441 lseek(tcs->masterfd, idxid * sizeof(struct index_entry) 441 lseek(masterfd, idxid * sizeof(struct index_entry)
442 + sizeof(struct master_header), SEEK_SET); 442 + sizeof(struct master_header), SEEK_SET);
443 if (read(tcs->masterfd, idx, sizeof(struct index_entry)) != 443 if (read(masterfd, idx, sizeof(struct index_entry)) !=
444 sizeof(struct index_entry)) 444 sizeof(struct index_entry))
445 { 445 {
446 logf("read error #3"); 446 logf("read error #3");
447 return false; 447 return false;
448 } 448 }
449 449
450 if (idx->flag & FLAG_DELETED)
451 return false;
452
453 return true;
454}
455
456static bool write_index(int masterfd, int idxid, struct index_entry *idx)
457{
458#ifdef HAVE_TC_RAMCACHE
459 if (stat.ramcache)
460 memcpy(&hdr->indices[idxid], idx, sizeof(struct index_entry));
461#endif
462
463 lseek(masterfd, idxid * sizeof(struct index_entry)
464 + sizeof(struct master_header), SEEK_SET);
465 if (write(masterfd, idx, sizeof(struct index_entry)) !=
466 sizeof(struct index_entry))
467 {
468 logf("write error #3");
469 return false;
470 }
471
450 return true; 472 return true;
451} 473}
452 474
@@ -487,7 +509,7 @@ long tagcache_get_numeric(const struct tagcache_search *tcs, int tag)
487 if (!tagcache_is_numeric_tag(tag)) 509 if (!tagcache_is_numeric_tag(tag))
488 return -1; 510 return -1;
489 511
490 if (!tagcache_get_index(tcs, tcs->idx_id, &idx)) 512 if (!get_index(tcs->masterfd, tcs->idx_id, &idx))
491 return -2; 513 return -2;
492 514
493 return check_virtual_tags(tag, &idx); 515 return check_virtual_tags(tag, &idx);
@@ -991,7 +1013,7 @@ bool tagcache_retrieve(struct tagcache_search *tcs, int idxid,
991 struct index_entry idx; 1013 struct index_entry idx;
992 long seek; 1014 long seek;
993 1015
994 if (!tagcache_get_index(tcs, idxid, &idx)) 1016 if (!get_index(tcs->masterfd, idxid, &idx))
995 return false; 1017 return false;
996 1018
997 seek = idx.tag_seek[tcs->type]; 1019 seek = idx.tag_seek[tcs->type];
@@ -2137,6 +2159,8 @@ static bool commit(void)
2137 tagcache_start_scan(); 2159 tagcache_start_scan();
2138#endif 2160#endif
2139 2161
2162 queue_post(&tagcache_queue, Q_IMPORT_CHANGELOG, 0);
2163
2140 return true; 2164 return true;
2141} 2165}
2142 2166
@@ -2208,37 +2232,13 @@ static bool modify_numeric_entry(int masterfd, int idx_id, int tag, long data)
2208 if (!tagcache_is_numeric_tag(tag)) 2232 if (!tagcache_is_numeric_tag(tag))
2209 return false; 2233 return false;
2210 2234
2211#ifdef HAVE_TC_RAMCACHE 2235 if (!get_index(masterfd, idx_id, &idx))
2212 /* Update ram entries first. */
2213 if (hdr)
2214 {
2215 hdr->indices[idx_id].tag_seek[tag] = data;
2216 hdr->indices[idx_id].flag |= FLAG_DIRTYNUM;
2217 }
2218#endif
2219
2220 /* And now update the db on disk also. */
2221 lseek(masterfd, idx_id * sizeof(struct index_entry)
2222 + sizeof(struct master_header), SEEK_SET);
2223 if (read(masterfd, &idx, sizeof(struct index_entry))
2224 != sizeof(struct index_entry))
2225 {
2226 logf("read error");
2227 return false; 2236 return false;
2228 }
2229 2237
2230 idx.flag |= FLAG_DIRTYNUM;
2231 idx.tag_seek[tag] = data; 2238 idx.tag_seek[tag] = data;
2239 idx.flag |= FLAG_DIRTYNUM;
2232 2240
2233 lseek(masterfd, -sizeof(struct index_entry), SEEK_CUR); 2241 return write_index(masterfd, idx_id, &idx);
2234 if (write(masterfd, &idx, sizeof(struct index_entry))
2235 != sizeof(struct index_entry))
2236 {
2237 logf("write error");
2238 return false;
2239 }
2240
2241 return true;
2242} 2242}
2243 2243
2244bool tagcache_modify_numeric_entry(struct tagcache_search *tcs, 2244bool tagcache_modify_numeric_entry(struct tagcache_search *tcs,
@@ -2357,6 +2357,7 @@ static bool read_tag(char *dest, long size,
2357 2357
2358static bool parse_changelog_line(int masterfd, const char *buf) 2358static bool parse_changelog_line(int masterfd, const char *buf)
2359{ 2359{
2360 struct index_entry idx;
2360 char tag_data[MAX_PATH]; 2361 char tag_data[MAX_PATH];
2361 int idx_id; 2362 int idx_id;
2362 const int import_tags[] = { tag_playcount, tag_playtime, tag_lastplayed }; 2363 const int import_tags[] = { tag_playcount, tag_playtime, tag_lastplayed };
@@ -2379,6 +2380,19 @@ static bool parse_changelog_line(int masterfd, const char *buf)
2379 return false; 2380 return false;
2380 } 2381 }
2381 2382
2383 if (!get_index(masterfd, idx_id, &idx))
2384 {
2385 logf("failed to retrieve index entry");
2386 return false;
2387 }
2388
2389 /* Stop if tag has already been modified. */
2390 if (idx.flag & FLAG_DIRTYNUM)
2391 return false;
2392
2393 logf("import: %s", tag_data);
2394
2395 idx.flag |= FLAG_DIRTYNUM;
2382 for (i = 0; i < (long)(sizeof(import_tags)/sizeof(import_tags[0])); i++) 2396 for (i = 0; i < (long)(sizeof(import_tags)/sizeof(import_tags[0])); i++)
2383 { 2397 {
2384 int data; 2398 int data;
@@ -2393,13 +2407,13 @@ static bool parse_changelog_line(int masterfd, const char *buf)
2393 if (data < 0) 2407 if (data < 0)
2394 continue; 2408 continue;
2395 2409
2396 modify_numeric_entry(masterfd, idx_id, import_tags[i], data); 2410 idx.tag_seek[import_tags[i]] = data;
2397 2411
2398 if (import_tags[i] == tag_lastplayed && data > current_serial) 2412 if (import_tags[i] == tag_lastplayed && data > current_serial)
2399 current_serial = data; 2413 current_serial = data;
2400 } 2414 }
2401 2415
2402 return true; 2416 return write_index(masterfd, idx_id, &idx);
2403} 2417}
2404 2418
2405bool tagcache_import_changelog(void) 2419bool tagcache_import_changelog(void)
@@ -3155,10 +3169,10 @@ static void tagcache_thread(void)
3155 3169
3156 switch (ev.id) 3170 switch (ev.id)
3157 { 3171 {
3158 case Q_START_SCAN: 3172 case Q_IMPORT_CHANGELOG:
3159 check_done = false; 3173 tagcache_import_changelog();
3160 break ; 3174 break;
3161 3175
3162 case Q_REBUILD: 3176 case Q_REBUILD:
3163 remove_files(); 3177 remove_files();
3164 build_tagcache(); 3178 build_tagcache();
@@ -3169,6 +3183,8 @@ static void tagcache_thread(void)
3169 check_deleted_files(); 3183 check_deleted_files();
3170 break ; 3184 break ;
3171 3185
3186 case Q_START_SCAN:
3187 check_done = false;
3172 case SYS_TIMEOUT: 3188 case SYS_TIMEOUT:
3173 if (check_done || !stat.ready) 3189 if (check_done || !stat.ready)
3174 break ; 3190 break ;
@@ -3191,7 +3207,8 @@ static void tagcache_thread(void)
3191 check_deleted_files(); 3207 check_deleted_files();
3192#endif 3208#endif
3193 } 3209 }
3194 3210
3211
3195 logf("tagcache check done"); 3212 logf("tagcache check done");
3196 check_done = true; 3213 check_done = true;
3197 break ; 3214 break ;