aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-09 19:17:25 +0200
committerMax Kellermann <max@duempel.org>2008-10-09 19:17:25 +0200
commit84b52265a604f7cfebf4a6d9b34a6efa007cd1d4 (patch)
treee50c21284c17a9d236c86da18bedfbc38283a323
parent9604f88fe772a0e69ff2790f9c9306bdc9f4f122 (diff)
downloadmpd-84b52265a604f7cfebf4a6d9b34a6efa007cd1d4.tar.gz
mpd-84b52265a604f7cfebf4a6d9b34a6efa007cd1d4.tar.xz
mpd-84b52265a604f7cfebf4a6d9b34a6efa007cd1d4.zip
update: eliminated addSubDirectoryToDirectory()
In updateInDirectory(), add new directories immediately and delete them when they turn out to be empty. This simplifies the code and allows us to eliminate addSubDirectoryToDirectory().
Diffstat (limited to '')
-rw-r--r--src/update.c35
1 files changed, 8 insertions, 27 deletions
diff --git a/src/update.c b/src/update.c
index a1c0a2f25..412f6c5ed 100644
--- a/src/update.c
+++ b/src/update.c
@@ -230,23 +230,6 @@ static enum update_return
updateDirectory(struct directory *directory, const struct stat *st);
static enum update_return
-addSubDirectoryToDirectory(struct directory *directory,
- const char *name, const struct stat *st)
-{
- struct directory *subDirectory;
-
- subDirectory = directory_new(name, directory);
- if (updateDirectory(subDirectory, st) != UPDATE_RETURN_UPDATED) {
- directory_free(subDirectory);
- return UPDATE_RETURN_NOUPDATE;
- }
-
- dirvec_add(&directory->children, subDirectory);
-
- return UPDATE_RETURN_UPDATED;
-}
-
-static enum update_return
updateInDirectory(struct directory *directory,
const char *name, const struct stat *st)
{
@@ -270,24 +253,22 @@ updateInDirectory(struct directory *directory,
}
} else if (S_ISDIR(st->st_mode)) {
struct directory *subdir;
+ enum update_return ret;
if (inodeFoundInParent(directory, st->st_ino, st->st_dev))
return UPDATE_RETURN_ERROR;
subdir = directory_get_child(directory, name);
- if (subdir) {
- enum update_return ret;
+ if (subdir == NULL)
+ subdir = directory_new_child(directory, name);
- assert(directory == subdir->parent);
+ assert(directory == subdir->parent);
- ret = updateDirectory(subdir, st);
- if (ret == UPDATE_RETURN_ERROR)
- delete_directory(subdir);
+ ret = updateDirectory(subdir, st);
+ if (ret == UPDATE_RETURN_ERROR || directory_is_empty(subdir))
+ delete_directory(subdir);
- return ret;
- } else {
- return addSubDirectoryToDirectory(directory, name, st);
- }
+ return ret;
}
DEBUG("update: %s is not a directory or music\n", name);