Commit e79aacf1 authored by Max Kellermann's avatar Max Kellermann

directory: added directory_is_empty()

directory_is_empty() is a tiny inline function which determine if a directory has any child objects (sub directories or songs).
parent 7b9bed83
......@@ -89,7 +89,7 @@ static void deleteEmptyDirectoriesInDirectory(Directory * directory)
for (i = dv->nr; --i >= 0; ) {
deleteEmptyDirectoriesInDirectory(dv->base[i]);
if (!dv->base[i]->children.nr && !dv->base[i]->songs.nr)
if (directory_is_empty(dv->base[i]))
dirvec_delete(dv, dv->base[i]);
}
if (!dv->nr)
......
......@@ -23,6 +23,8 @@
#include "songvec.h"
#include "list.h"
#include <stdbool.h>
struct dirvec {
struct _Directory **base;
size_t nr;
......@@ -53,6 +55,12 @@ newDirectory(const char *dirname, Directory * parent);
void
freeDirectory(Directory * directory);
static inline bool
directory_is_empty(Directory *directory)
{
return directory->children.nr == 0 && directory->songs.nr == 0;
}
Directory *
getDirectory(const char *name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment