aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-09 19:17:25 +0200
committerEric Wong <normalperson@yhbt.net>2008-10-11 19:21:51 -0700
commit516540ba565d47c79ac18f8bfe395e0d38598fea (patch)
tree5b526a6cb231cb388a800ad3832f11c2f68bc494
parent7945d695e5ebcfea8e41e0c3b2dc5b72f8b0a0b9 (diff)
downloadmpd-516540ba565d47c79ac18f8bfe395e0d38598fea.tar.gz
mpd-516540ba565d47c79ac18f8bfe395e0d38598fea.tar.xz
mpd-516540ba565d47c79ac18f8bfe395e0d38598fea.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().
-rw-r--r--src/update.c35
1 files changed, 8 insertions, 27 deletions
diff --git a/src/update.c b/src/update.c
index a1e33ba22..69ae9794d 100644
--- a/src/update.c
+++ b/src/update.c
@@ -219,23 +219,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)
{
@@ -257,23 +240,21 @@ 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;
- if ((subdir = directory_get_child(directory, name))) {
- enum update_return ret;
+ if (!(subdir = directory_get_child(directory, name)))
+ 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);