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
This commit is contained in:
parent
c7d9c8b7dd
commit
996e8ce072
|
@ -59,7 +59,7 @@ typedef struct _Directory {
|
||||||
time_t mtime; /* modification time */
|
time_t mtime; /* modification time */
|
||||||
} Directory;
|
} Directory;
|
||||||
|
|
||||||
Directory * mp3rootDirectory;
|
Directory * mp3rootDirectory = NULL;
|
||||||
|
|
||||||
char directorydb[MAXPATHLEN+1];
|
char directorydb[MAXPATHLEN+1];
|
||||||
|
|
||||||
|
@ -438,6 +438,9 @@ void readDirectoryInfo(FILE * fp,Directory * directory) {
|
||||||
Directory * subDirectory;
|
Directory * subDirectory;
|
||||||
char * name;
|
char * name;
|
||||||
time_t mtime;
|
time_t mtime;
|
||||||
|
int strcmpRet;
|
||||||
|
ListNode * nextDirNode = directory->subDirectories->firstNode;
|
||||||
|
ListNode * nodeTemp;
|
||||||
|
|
||||||
while(myFgets(buffer,bufferSize,fp) && 0!=strncmp(DIRECTORY_END,buffer,strlen(DIRECTORY_END))) {
|
while(myFgets(buffer,bufferSize,fp) && 0!=strncmp(DIRECTORY_END,buffer,strlen(DIRECTORY_END))) {
|
||||||
if(0==strncmp(DIRECTORY_DIR,buffer,strlen(DIRECTORY_DIR))) {
|
if(0==strncmp(DIRECTORY_DIR,buffer,strlen(DIRECTORY_DIR))) {
|
||||||
|
@ -461,8 +464,36 @@ void readDirectoryInfo(FILE * fp,Directory * directory) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
name = strdup(&(buffer[strlen(DIRECTORY_BEGIN)]));
|
name = strdup(&(buffer[strlen(DIRECTORY_BEGIN)]));
|
||||||
subDirectory = newDirectory(directory,name,mtime);
|
|
||||||
insertInList(directory->subDirectories,key,(void *)subDirectory);
|
while(nextDirNode && (strcmpRet =
|
||||||
|
strcmp(key,nextDirNode->key)) > 0) {
|
||||||
|
nodeTemp = nextDirNode->nextNode;
|
||||||
|
deleteNodeFromList(directory->subDirectories,
|
||||||
|
nextDirNode);
|
||||||
|
nextDirNode = nodeTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!nextDirNode) {
|
||||||
|
subDirectory = newDirectory(directory,name,
|
||||||
|
mtime);
|
||||||
|
insertInList(directory->subDirectories,key,
|
||||||
|
(void *)subDirectory);
|
||||||
|
}
|
||||||
|
else if(strcmpRet == 0) {
|
||||||
|
subDirectory = (Directory *)nextDirNode->data;
|
||||||
|
subDirectory->mtime = mtime;
|
||||||
|
nextDirNode = nextDirNode->nextNode;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
subDirectory = newDirectory(directory,name,
|
||||||
|
mtime);
|
||||||
|
insertInListBeforeNode(
|
||||||
|
directory->subDirectories,
|
||||||
|
nextDirNode,
|
||||||
|
key,
|
||||||
|
(void *)subDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
free(key);
|
free(key);
|
||||||
free(name);
|
free(name);
|
||||||
readDirectoryInfo(fp,subDirectory);
|
readDirectoryInfo(fp,subDirectory);
|
||||||
|
@ -475,6 +506,12 @@ void readDirectoryInfo(FILE * fp,Directory * directory) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while(nextDirNode) {
|
||||||
|
nodeTemp = nextDirNode->nextNode;
|
||||||
|
deleteNodeFromList(directory->subDirectories,nextDirNode);
|
||||||
|
nextDirNode = nodeTemp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sortDirectory(Directory * directory) {
|
void sortDirectory(Directory * directory) {
|
||||||
|
@ -516,7 +553,7 @@ int writeDirectoryDB() {
|
||||||
int readDirectoryDB() {
|
int readDirectoryDB() {
|
||||||
FILE * fp;
|
FILE * fp;
|
||||||
|
|
||||||
mp3rootDirectory = newDirectory(NULL,NULL,0);
|
if(!mp3rootDirectory) mp3rootDirectory = newDirectory(NULL,NULL,0);
|
||||||
while(!(fp=fopen(directorydb,"r")) && errno==EINTR);
|
while(!(fp=fopen(directorydb,"r")) && errno==EINTR);
|
||||||
if(!fp) return -1;
|
if(!fp) return -1;
|
||||||
|
|
||||||
|
|
59
src/song.c
59
src/song.c
|
@ -104,6 +104,12 @@ void freeSong(Song * song) {
|
||||||
free(song);
|
free(song);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void freeJustSong(Song * song) {
|
||||||
|
free(song->utf8file);
|
||||||
|
if(song->tag) freeMpdTag(song->tag);
|
||||||
|
free(song);
|
||||||
|
}
|
||||||
|
|
||||||
SongList * newSongList() {
|
SongList * newSongList() {
|
||||||
return makeList((ListFreeDataFunc *)freeSong);
|
return makeList((ListFreeDataFunc *)freeSong);
|
||||||
}
|
}
|
||||||
|
@ -160,19 +166,58 @@ void writeSongInfoFromList(FILE * fp, SongList * list) {
|
||||||
myfprintf(fp,"%s\n",SONG_END);
|
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) {
|
void readSongInfoIntoList(FILE * fp, SongList * list) {
|
||||||
char buffer[MAXPATHLEN+1024];
|
char buffer[MAXPATHLEN+1024];
|
||||||
int bufferSize = MAXPATHLEN+1024;
|
int bufferSize = MAXPATHLEN+1024;
|
||||||
Song * song = NULL;
|
Song * song = NULL;
|
||||||
char * key = NULL;
|
char * key = NULL;
|
||||||
|
ListNode * nextSongNode = list->firstNode;
|
||||||
|
ListNode * nodeTemp;
|
||||||
|
|
||||||
while(myFgets(buffer,bufferSize,fp) && 0!=strcmp(SONG_END,buffer)) {
|
while(myFgets(buffer,bufferSize,fp) && 0!=strcmp(SONG_END,buffer)) {
|
||||||
if(0==strncmp(SONG_KEY,buffer,strlen(SONG_KEY))) {
|
if(0==strncmp(SONG_KEY,buffer,strlen(SONG_KEY))) {
|
||||||
if(song) {
|
if(song) {
|
||||||
insertInList(list,key,(void *)song);
|
insertSongIntoList(list,&nextSongNode,key,song);
|
||||||
addSongToTables(song);
|
song = NULL;
|
||||||
free(key);
|
free(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
key = strdup(&(buffer[strlen(SONG_KEY)]));
|
key = strdup(&(buffer[strlen(SONG_KEY)]));
|
||||||
song = newNullSong();
|
song = newNullSong();
|
||||||
}
|
}
|
||||||
|
@ -213,10 +258,16 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(song) {
|
if(song) {
|
||||||
insertInList(list,key,(void *)song);
|
insertSongIntoList(list,&nextSongNode,key,song);
|
||||||
addSongToTables(song);
|
song = NULL;
|
||||||
free(key);
|
free(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while(nextSongNode) {
|
||||||
|
nodeTemp = nextSongNode->nextNode;
|
||||||
|
deleteNodeFromList(list,nextSongNode);
|
||||||
|
nextSongNode = nodeTemp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int updateSongInfo(Song * song) {
|
int updateSongInfo(Song * song) {
|
||||||
|
|
Loading…
Reference in New Issue