aboutsummaryrefslogtreecommitdiffstats
path: root/src/update.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-10-11 23:04:36 -0700
committerEric Wong <normalperson@yhbt.net>2008-10-12 05:27:33 -0700
commite018b35b0d99d24e1f3779fd51c07154b370eca9 (patch)
tree236e61c9c8e69317079e8c2796f6aa5c875bc763 /src/update.c
parent4111d84ad5b72f871d35f76a47765c138a201611 (diff)
downloadmpd-e018b35b0d99d24e1f3779fd51c07154b370eca9.tar.gz
mpd-e018b35b0d99d24e1f3779fd51c07154b370eca9.tar.xz
mpd-e018b35b0d99d24e1f3779fd51c07154b370eca9.zip
dirvec: use dirvec_for_each where it makes sense
This way we can introduce locking to allow safe traversals from the main thread while we're updating.
Diffstat (limited to '')
-rw-r--r--src/update.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/update.c b/src/update.c
index 35605ee51..99a58a06e 100644
--- a/src/update.c
+++ b/src/update.c
@@ -91,15 +91,12 @@ static int delete_each_song(struct mpd_song *song, mpd_unused void *data)
* Recursively remove all sub directories and songs from a directory,
* leaving an empty directory.
*/
-static void clear_directory(struct directory *dir)
+static int clear_directory(struct directory *dir, mpd_unused void *arg)
{
- int i;
-
- for (i = dir->children.nr; --i >= 0;)
- clear_directory(dir->children.base[i]);
+ dirvec_for_each(&dir->children, clear_directory, NULL);
dirvec_clear(&dir->children);
-
songvec_for_each(&dir->songs, delete_each_song, dir);
+ return 0;
}
/**
@@ -109,7 +106,7 @@ static void delete_directory(struct directory *dir)
{
assert(dir->parent != NULL);
- clear_directory(dir);
+ clear_directory(dir, NULL);
dirvec_delete(&dir->parent->children, dir);
directory_free(dir);
}
@@ -149,23 +146,27 @@ static void delete_path(const char *path)
}
}
-static void
-removeDeletedFromDirectory(char *path_max_tmp, struct directory *dir)
+/* passed to dirvec_for_each */
+static int delete_directory_if_removed(struct directory *dir, void *_data)
{
- int i;
- struct dirvec *dv = &dir->children;
- struct delete_data data;
+ if (!isDir(dir->path)) {
+ struct delete_data *data = _data;
- for (i = dv->nr; --i >= 0; ) {
- if (isDir(dv->base[i]->path))
- continue;
- LOG("removing directory: %s\n", dv->base[i]->path);
- dirvec_delete(dv, dv->base[i]);
+ LOG("removing directory: %s\n", directory_get_path(dir));
+ dirvec_delete(&data->dir->children, dir);
modified = 1;
}
+ return 0;
+}
+
+static void
+removeDeletedFromDirectory(char *path_max_tmp, struct directory *dir)
+{
+ struct delete_data data;
data.dir = dir;
data.tmp = path_max_tmp;
+ dirvec_for_each(&dir->children, delete_directory_if_removed, &data);
songvec_for_each(&dir->songs, delete_song_if_removed, &data);
}