aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-03-09 22:48:35 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-03-09 22:48:35 +0000
commite1296401410a80bf564c13a592db0a4b20d732e0 (patch)
tree575786d276f60e3896bec34047292ebf1c31317f /src
parent8d95265cc8ba60ed8f51a07a6028f4a0dc56bf6d (diff)
downloadmpd-e1296401410a80bf564c13a592db0a4b20d732e0.tar.gz
mpd-e1296401410a80bf564c13a592db0a4b20d732e0.tar.xz
mpd-e1296401410a80bf564c13a592db0a4b20d732e0.zip
remove empty directories
git-svn-id: https://svn.musicpd.org/mpd/trunk@233 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src')
-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);