diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-04-16 23:49:48 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-04-16 23:49:48 +0000 |
commit | 158c23f23850b6c10a596ee8f003344ff1871302 (patch) | |
tree | 31b851ad2bd34eb260cbc660386419481bd0d3f7 /src | |
parent | 4a1fbb45c5a5ccffa03bf9a847b996c2f0d9ee39 (diff) | |
download | mpd-158c23f23850b6c10a596ee8f003344ff1871302.tar.gz mpd-158c23f23850b6c10a596ee8f003344ff1871302.tar.xz mpd-158c23f23850b6c10a596ee8f003344ff1871302.zip |
when updating, don't cause db reread on adding and then removing empty directories
git-svn-id: https://svn.musicpd.org/mpd/trunk@805 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src')
-rw-r--r-- | src/directory.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/src/directory.c b/src/directory.c index 495173fdd..ed0992021 100644 --- a/src/directory.c +++ b/src/directory.c @@ -103,7 +103,7 @@ void deleteEmptyDirectoriesInDirectory(Directory * directory); void removeSongFromDirectory(Directory * directory, char * shortname); -Directory * addSubDirectoryToDirectory(Directory * directory, char * shortname, +int addSubDirectoryToDirectory(Directory * directory, char * shortname, char * name); Directory * getDirectoryDetails(char * name, char ** shortname, @@ -328,8 +328,8 @@ int updateInDirectory(Directory * directory, char * shortname, char * name) { if(updateDirectory((Directory *)subDir)>0) return 1; } else { - addSubDirectoryToDirectory(directory,shortname,name); - return 1; + return addSubDirectoryToDirectory(directory,shortname, + name); } } @@ -434,8 +434,9 @@ Directory * addDirectoryPathToDB(char * utf8path, char ** shortname) { if(!findInList(parentDirectory->subDirectories,*shortname, &directory)) { - directory = (void *)addSubDirectoryToDirectory(parentDirectory, - *shortname,utf8path); + directory = newDirectory(utf8path); + insertInList(parentDirectory->subDirectories,*shortname, + directory); } /* if we're adding directory paths, make sure to delete filenames @@ -531,9 +532,7 @@ int updatePath(char * utf8path) { */ if(isDir(path) || isMusic(path,NULL)) { parentDirectory = addParentPathToDB(path,&shortname); - addToDirectory(parentDirectory,shortname,path); - sortDirectory(parentDirectory); - ret = 1; + if(addToDirectory(parentDirectory,shortname,path)>0) ret = 1; } free(path); @@ -587,6 +586,11 @@ int updateDirectory(Directory * directory) { return ret; } +/* return values: + -1 -> error + 0 -> no error, but nothing found + 1 -> no error, and stuff found + */ int exploreDirectory(Directory * directory) { DIR * dir; char cwd[2]; @@ -594,6 +598,7 @@ int exploreDirectory(Directory * directory) { char * s; char * utf8; char * dirname = directory->utf8name; + int ret = 0; cwd[0] = '.'; cwd[1] = '\0'; @@ -619,38 +624,41 @@ int exploreDirectory(Directory * directory) { sprintf(s,"%s/%s",directory->utf8name,utf8); } else s = strdup(utf8); - addToDirectory(directory,utf8,s); + if(addToDirectory(directory,utf8,s)>0) ret = 1; free(utf8); free(s); } closedir(dir); - return 0; + return ret; } -Directory * addSubDirectoryToDirectory(Directory * directory, char * shortname, +int addSubDirectoryToDirectory(Directory * directory, char * shortname, char * name) { Directory * subDirectory = newDirectory(name); + if(exploreDirectory(subDirectory)<1) { + freeDirectory(subDirectory); + return 0; + } + insertInList(directory->subDirectories,shortname,subDirectory); - exploreDirectory(subDirectory); - return subDirectory; + return 1; } int addToDirectory(Directory * directory, char * shortname, char * name) { if(isDir(name)) { - addSubDirectoryToDirectory(directory,shortname,name); - return 0; + return addSubDirectoryToDirectory(directory,shortname,name); } else if(isMusic(name,NULL)) { Song * song; song = addSongToList(directory->songs,shortname,name); if(!song) return -1; LOG("added %s\n",name); - return 0; + return 1; } DEBUG("addToDirectory: %s is not a directory or music\n",name); |