aboutsummaryrefslogtreecommitdiffstats
path: root/src/song.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-04-10 17:56:01 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-04-10 17:56:01 +0000
commit996e8ce072838c424dd6a54dc6eb1be06a939345 (patch)
tree8bfac6391f2b1c4a63e7a80c4a99bace57d59750 /src/song.c
parentc7d9c8b7dd8eefa830beb4d1d39e01b9f9176ac7 (diff)
downloadmpd-996e8ce072838c424dd6a54dc6eb1be06a939345.tar.gz
mpd-996e8ce072838c424dd6a54dc6eb1be06a939345.tar.xz
mpd-996e8ce072838c424dd6a54dc6eb1be06a939345.zip
work in prep of using msells/sbh's non-blocking update method
Here, i've made readDirectoryDB detect when stuff is deleted, added and updated. So after a update, and we call redDirectoryDB, we update the db instead of just adding stuff w/o "updating" and "deleting" stuff as neccessary. git-svn-id: https://svn.musicpd.org/mpd/trunk@659 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/song.c')
-rw-r--r--src/song.c59
1 files changed, 55 insertions, 4 deletions
diff --git a/src/song.c b/src/song.c
index 826fbceb8..7cf327080 100644
--- a/src/song.c
+++ b/src/song.c
@@ -104,6 +104,12 @@ void freeSong(Song * song) {
free(song);
}
+void freeJustSong(Song * song) {
+ free(song->utf8file);
+ if(song->tag) freeMpdTag(song->tag);
+ free(song);
+}
+
SongList * newSongList() {
return makeList((ListFreeDataFunc *)freeSong);
}
@@ -160,19 +166,58 @@ void writeSongInfoFromList(FILE * fp, SongList * list) {
myfprintf(fp,"%s\n",SONG_END);
}
+void insertSongIntoList(SongList * list, ListNode ** nextSongNode, char * key,
+ Song * song)
+{
+ ListNode * nodeTemp;
+ int cmpRet= 0;
+
+ while(*nextSongNode && (cmpRet = strcmp(key,(*nextSongNode)->key)) > 0)
+ {
+ nodeTemp = (*nextSongNode)->nextNode;
+ deleteNodeFromList(list,*nextSongNode);
+ *nextSongNode = nodeTemp;
+ }
+
+ if(!(*nextSongNode)) {
+ insertInList(list,key,(void *)song);
+ addSongToTables(song);
+ }
+ else if(cmpRet == 0) {
+ Song * tempSong = (Song *)((*nextSongNode)->data);
+ if(tempSong->mtime != song->mtime) {
+ removeASongFromTables(tempSong);
+ freeMpdTag(tempSong->tag);
+ tempSong->tag = song->tag;
+ tempSong->mtime = song->mtime;
+ song->tag = NULL;
+ freeJustSong(song);
+ addSongToTables(tempSong);
+ }
+ *nextSongNode = (*nextSongNode)->nextNode;
+ }
+ else {
+ addSongToTables(song);
+ insertInListBeforeNode(list,*nextSongNode,key,(void *)song);
+ }
+}
+
void readSongInfoIntoList(FILE * fp, SongList * list) {
char buffer[MAXPATHLEN+1024];
int bufferSize = MAXPATHLEN+1024;
Song * song = NULL;
char * key = NULL;
+ ListNode * nextSongNode = list->firstNode;
+ ListNode * nodeTemp;
while(myFgets(buffer,bufferSize,fp) && 0!=strcmp(SONG_END,buffer)) {
if(0==strncmp(SONG_KEY,buffer,strlen(SONG_KEY))) {
if(song) {
- insertInList(list,key,(void *)song);
- addSongToTables(song);
+ insertSongIntoList(list,&nextSongNode,key,song);
+ song = NULL;
free(key);
}
+
key = strdup(&(buffer[strlen(SONG_KEY)]));
song = newNullSong();
}
@@ -213,10 +258,16 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
}
if(song) {
- insertInList(list,key,(void *)song);
- addSongToTables(song);
+ insertSongIntoList(list,&nextSongNode,key,song);
+ song = NULL;
free(key);
}
+
+ while(nextSongNode) {
+ nodeTemp = nextSongNode->nextNode;
+ deleteNodeFromList(list,nextSongNode);
+ nextSongNode = nodeTemp;
+ }
}
int updateSongInfo(Song * song) {