aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-10-13 22:10:52 -0700
committerEric Wong <normalperson@yhbt.net>2008-10-13 22:10:52 -0700
commit65688ec9e8841fb11c166d3e480dbada01d99746 (patch)
tree971612f577d2f0f5997717a783c3891e3978fc0d
parent396f03db551d585ee3eff4a3a1e6f49283abbc61 (diff)
downloadmpd-65688ec9e8841fb11c166d3e480dbada01d99746.tar.gz
mpd-65688ec9e8841fb11c166d3e480dbada01d99746.tar.xz
mpd-65688ec9e8841fb11c166d3e480dbada01d99746.zip
directory: avoid magic in directory_walk
magically changing what directory_walk does based on a particular function pointer it got passed is bad.
-rw-r--r--src/directory.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/src/directory.c b/src/directory.c
index fe9e83405..70d7dafe0 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -49,24 +49,34 @@ static int free_each_song(struct mpd_song *song, mpd_unused void *arg)
return 0;
}
-static int free_each_dir(struct directory *dir, mpd_unused void *arg)
+static int free_each_dir(struct directory *dir, void *arg)
+{
+ if (dir != arg) {
+ assert(dir != &music_root);
+ assert(dir->parent);
+ dirvec_delete(&dir->parent->children, dir);
+ assert(!dir->songs.nr);
+ assert(!dir->songs.base);
+ assert(!dir->children.nr);
+ assert(!dir->children.base);
+ free(dir);
+ }
+ return 0;
+}
+
+void directory_free(struct directory *dir)
{
if (dir != &music_root) {
assert(dir->parent);
dirvec_delete(&dir->parent->children, dir);
}
+ directory_walk(dir, free_each_song, free_each_dir, dir);
assert(!dir->songs.nr);
assert(!dir->songs.base);
assert(!dir->children.nr);
assert(!dir->children.base);
if (dir != &music_root)
free(dir);
- return 0;
-}
-
-void directory_free(struct directory *dir)
-{
- directory_walk(dir, free_each_song, free_each_dir, NULL);
}
static int dir_pruner(struct directory *dir, void *_dv)
@@ -135,9 +145,8 @@ int directory_walk(struct directory *dir,
{
int err = 0;
- if (forEachDir && forEachDir != free_each_dir)
- if ((err = forEachDir(dir, data)) < 0)
- return err;
+ if (forEachDir && (err = forEachDir(dir, data)) < 0)
+ return err;
if (forEachSong) {
err = songvec_for_each(&dir->songs, forEachSong, data);
@@ -153,8 +162,6 @@ int directory_walk(struct directory *dir,
dw_arg.data = data;
err = dirvec_for_each(&dir->children, dirwalk_x, &dw_arg);
}
- if (forEachDir == free_each_dir)
- if ((err = forEachDir(dir, data)) < 0)
- return err;
+
return err;
}