diff options
Diffstat (limited to 'src/directory.c')
-rw-r--r-- | src/directory.c | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/src/directory.c b/src/directory.c index fa15d41b1..380232761 100644 --- a/src/directory.c +++ b/src/directory.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2010 The Music Player Daemon Project + * Copyright (C) 2003-2011 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -21,6 +21,7 @@ #include "directory.h" #include "song.h" #include "path.h" +#include "db_visitor.h" #include <glib.h> @@ -167,28 +168,42 @@ directory_sort(struct directory *directory) directory_sort(dv->base[i]); } -int -directory_walk(struct directory *directory, - int (*forEachSong)(struct song *, void *), - int (*forEachDir)(struct directory *, void *), - void *data) +bool +directory_walk(const struct directory *directory, bool recursive, + const struct db_visitor *visitor, void *ctx, + GError **error_r) { - struct dirvec *dv = &directory->children; - int err = 0; - size_t j; - - if (forEachDir && (err = forEachDir(directory, data)) < 0) - return err; + assert(directory != NULL); + assert(visitor != NULL); + assert(error_r == NULL || *error_r == NULL); + + if (visitor->song != NULL) { + const struct songvec *sv = &directory->songs; + for (size_t i = 0; i < sv->nr; ++i) + if (!visitor->song(sv->base[i], ctx, error_r)) + return false; + } - if (forEachSong) { - err = songvec_for_each(&directory->songs, forEachSong, data); - if (err < 0) - return err; + if (visitor->playlist != NULL) { + const struct playlist_vector *pv = &directory->playlists; + for (const struct playlist_metadata *i = pv->head; + i != NULL; i = i->next) + if (!visitor->playlist(i, directory, ctx, error_r)) + return false; } - for (j = 0; err >= 0 && j < dv->nr; ++j) - err = directory_walk(dv->base[j], forEachSong, - forEachDir, data); + const struct dirvec *dv = &directory->children; + for (size_t i = 0; i < dv->nr; ++i) { + struct directory *child = dv->base[i]; + + if (visitor->directory != NULL && + !visitor->directory(child, ctx, error_r)) + return false; + + if (recursive && + !directory_walk(child, recursive, visitor, ctx, error_r)) + return false; + } - return err; + return true; } |