diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-04-10 17:56:01 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-04-10 17:56:01 +0000 |
commit | 996e8ce072838c424dd6a54dc6eb1be06a939345 (patch) | |
tree | 8bfac6391f2b1c4a63e7a80c4a99bace57d59750 /src/directory.c | |
parent | c7d9c8b7dd8eefa830beb4d1d39e01b9f9176ac7 (diff) | |
download | mpd-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 '')
-rw-r--r-- | src/directory.c | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/src/directory.c b/src/directory.c index 3da1a0517..4ef4af10b 100644 --- a/src/directory.c +++ b/src/directory.c @@ -59,7 +59,7 @@ typedef struct _Directory { time_t mtime; /* modification time */ } Directory; -Directory * mp3rootDirectory; +Directory * mp3rootDirectory = NULL; char directorydb[MAXPATHLEN+1]; @@ -438,6 +438,9 @@ void readDirectoryInfo(FILE * fp,Directory * directory) { Directory * subDirectory; char * name; 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))) { if(0==strncmp(DIRECTORY_DIR,buffer,strlen(DIRECTORY_DIR))) { @@ -461,8 +464,36 @@ void readDirectoryInfo(FILE * fp,Directory * directory) { exit(EXIT_FAILURE); } 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(name); readDirectoryInfo(fp,subDirectory); @@ -475,6 +506,12 @@ void readDirectoryInfo(FILE * fp,Directory * directory) { exit(EXIT_FAILURE); } } + + while(nextDirNode) { + nodeTemp = nextDirNode->nextNode; + deleteNodeFromList(directory->subDirectories,nextDirNode); + nextDirNode = nodeTemp; + } } void sortDirectory(Directory * directory) { @@ -516,7 +553,7 @@ int writeDirectoryDB() { int readDirectoryDB() { FILE * fp; - mp3rootDirectory = newDirectory(NULL,NULL,0); + if(!mp3rootDirectory) mp3rootDirectory = newDirectory(NULL,NULL,0); while(!(fp=fopen(directorydb,"r")) && errno==EINTR); if(!fp) return -1; |