summaryrefslogtreecommitdiff
path: root/apps/tagcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tagcache.c')
-rw-r--r--apps/tagcache.c55
1 files changed, 12 insertions, 43 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 38537b5ceb..bf20927d95 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -72,6 +72,7 @@
72#include "atoi.h" 72#include "atoi.h"
73#include "crc32.h" 73#include "crc32.h"
74#include "eeprom_settings.h" 74#include "eeprom_settings.h"
75#include "misc.h"
75 76
76/* Tag Cache thread. */ 77/* Tag Cache thread. */
77static struct event_queue tagcache_queue; 78static struct event_queue tagcache_queue;
@@ -2687,40 +2688,42 @@ static bool read_tag(char *dest, long size,
2687 return false; 2688 return false;
2688} 2689}
2689 2690
2690static bool parse_changelog_line(int masterfd, const char *buf) 2691static int parse_changelog_line(int line_n, const char *buf, void *parameters)
2691{ 2692{
2692 struct index_entry idx; 2693 struct index_entry idx;
2693 char tag_data[MAX_PATH]; 2694 char tag_data[MAX_PATH];
2694 int idx_id; 2695 int idx_id;
2696 int masterfd = (int)parameters;
2695 const int import_tags[] = { tag_playcount, tag_playtime, tag_lastplayed }; 2697 const int import_tags[] = { tag_playcount, tag_playtime, tag_lastplayed };
2696 int i; 2698 int i;
2699 (void)line_n;
2697 2700
2698 if (*buf == '#') 2701 if (*buf == '#')
2699 return true; 2702 return 0;
2700 2703
2701 if (!read_tag(tag_data, sizeof tag_data, buf, "filename")) 2704 if (!read_tag(tag_data, sizeof tag_data, buf, "filename"))
2702 { 2705 {
2703 logf("filename missing"); 2706 logf("filename missing");
2704 logf("-> %s", buf); 2707 logf("-> %s", buf);
2705 return false; 2708 return -1;
2706 } 2709 }
2707 2710
2708 idx_id = find_index(tag_data); 2711 idx_id = find_index(tag_data);
2709 if (idx_id < 0) 2712 if (idx_id < 0)
2710 { 2713 {
2711 logf("entry not found"); 2714 logf("entry not found");
2712 return false; 2715 return -2;
2713 } 2716 }
2714 2717
2715 if (!get_index(masterfd, idx_id, &idx, false)) 2718 if (!get_index(masterfd, idx_id, &idx, false))
2716 { 2719 {
2717 logf("failed to retrieve index entry"); 2720 logf("failed to retrieve index entry");
2718 return false; 2721 return -3;
2719 } 2722 }
2720 2723
2721 /* Stop if tag has already been modified. */ 2724 /* Stop if tag has already been modified. */
2722 if (idx.flag & FLAG_DIRTYNUM) 2725 if (idx.flag & FLAG_DIRTYNUM)
2723 return false; 2726 return -4;
2724 2727
2725 logf("import: %s", tag_data); 2728 logf("import: %s", tag_data);
2726 2729
@@ -2745,7 +2748,7 @@ static bool parse_changelog_line(int masterfd, const char *buf)
2745 current_serial = data; 2748 current_serial = data;
2746 } 2749 }
2747 2750
2748 return write_index(masterfd, idx_id, &idx); 2751 return write_index(masterfd, idx_id, &idx) ? 0 : -5;
2749} 2752}
2750 2753
2751bool tagcache_import_changelog(void) 2754bool tagcache_import_changelog(void)
@@ -2754,7 +2757,6 @@ bool tagcache_import_changelog(void)
2754 struct tagcache_header tch; 2757 struct tagcache_header tch;
2755 int clfd, masterfd; 2758 int clfd, masterfd;
2756 char buf[2048]; 2759 char buf[2048];
2757 int pos = 0;
2758 2760
2759 if (!stat.ready) 2761 if (!stat.ready)
2760 return false; 2762 return false;
@@ -2779,41 +2781,8 @@ bool tagcache_import_changelog(void)
2779 2781
2780 filenametag_fd = open_tag_fd(&tch, tag_filename, false); 2782 filenametag_fd = open_tag_fd(&tch, tag_filename, false);
2781 2783
2782 /* Fast readline */ 2784 fast_readline(filenametag_fd, buf, sizeof buf, (void *)masterfd,
2783 while ( 1 ) 2785 parse_changelog_line);
2784 {
2785 char *p;
2786 char *next = NULL;
2787 int rc;
2788
2789 rc = read(clfd, &buf[pos], sizeof(buf)-pos-1);
2790 if (rc >= 0)
2791 buf[pos+rc] = '\0';
2792
2793 if ( (p = strchr(buf, '\r')) != NULL)
2794 {
2795 *p = '\0';
2796 next = ++p;
2797 }
2798 else
2799 p = buf;
2800
2801 if ( (p = strchr(p, '\n')) != NULL)
2802 {
2803 *p = '\0';
2804 next = ++p;
2805 }
2806
2807 parse_changelog_line(masterfd, buf);
2808
2809 if (next)
2810 {
2811 pos = sizeof(buf) - ((long)next - (long)buf) - 1;
2812 memmove(buf, next, pos);
2813 }
2814 else
2815 break ;
2816 }
2817 2786
2818 close(clfd); 2787 close(clfd);
2819 close(masterfd); 2788 close(masterfd);