remove empty directories

git-svn-id: https://svn.musicpd.org/mpd/trunk@233 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-03-09 22:48:35 +00:00
parent 8d95265cc8
commit e129640141
1 changed files with 21 additions and 0 deletions

View File

@ -76,6 +76,8 @@ int exploreDirectory(Directory * directory);
int updateDirectory(Directory * directory); int updateDirectory(Directory * directory);
void deleteEmptyDirectoriesInDirectory(Directory * directory);
int addSubDirectoryToDirectory(Directory * directory, char * shortname, char * name); int addSubDirectoryToDirectory(Directory * directory, char * shortname, char * name);
Directory * newDirectory(Directory * parentDirectory, char * dirname, time_t mtime) { Directory * newDirectory(Directory * parentDirectory, char * dirname, time_t mtime) {
@ -121,6 +123,24 @@ void removeSongFromDirectory(Directory * directory, char * shortname) {
} }
} }
void deleteEmptyDirectoriesInDirectory(Directory * directory) {
ListNode * node = directory->subDirectories->firstNode;
ListNode * nextNode;
Directory * subDir;
while(node) {
subDir = (Directory *)node->data;
deleteEmptyDirectoriesInDirectory(subDir);
nextNode = node->nextNode;
if(subDir->subDirectories->numberOfNodes==0 &&
subDir->songs->numberOfNodes==0)
{
deleteNodeFromList(directory->subDirectories,node);
}
node = nextNode;
}
}
int updateInDirectory(Directory * directory, char * shortname, char * name) { int updateInDirectory(Directory * directory, char * shortname, char * name) {
time_t mtime; time_t mtime;
void * song; void * song;
@ -475,6 +495,7 @@ void sortDirectory(Directory * directory) {
int writeDirectoryDB() { int writeDirectoryDB() {
FILE * fp; FILE * fp;
deleteEmptyDirectoriesInDirectory(mp3rootDirectory);
sortDirectory(mp3rootDirectory); sortDirectory(mp3rootDirectory);
stats.numberOfSongs = countSongsIn(stderr,NULL); stats.numberOfSongs = countSongsIn(stderr,NULL);
stats.dbPlayTime = sumSongTimesIn(stderr,NULL); stats.dbPlayTime = sumSongTimesIn(stderr,NULL);