summaryrefslogtreecommitdiff
path: root/src/directory.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/directory.c')
-rw-r--r--src/directory.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/directory.c b/src/directory.c
index 2b5009eca..90d1b622d 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -76,6 +76,8 @@ int exploreDirectory(Directory * directory);
int updateDirectory(Directory * directory);
+void deleteEmptyDirectoriesInDirectory(Directory * directory);
+
int addSubDirectoryToDirectory(Directory * directory, char * shortname, char * name);
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) {
time_t mtime;
void * song;
@@ -475,6 +495,7 @@ void sortDirectory(Directory * directory) {
int writeDirectoryDB() {
FILE * fp;
+ deleteEmptyDirectoriesInDirectory(mp3rootDirectory);
sortDirectory(mp3rootDirectory);
stats.numberOfSongs = countSongsIn(stderr,NULL);
stats.dbPlayTime = sumSongTimesIn(stderr,NULL);