aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-09 15:34:07 +0200
committerEric Wong <normalperson@yhbt.net>2008-10-11 19:21:49 -0700
commit4a13e19cebb8d72db6e2db9ffb9f9dbd7194ede9 (patch)
treee6b44e7f6c3bc4e3d30f3b88739dfb4f37ee2a28 /src
parentf2052e7e2ffb5b8ecd15d96a766b5a162a39b2af (diff)
downloadmpd-4a13e19cebb8d72db6e2db9ffb9f9dbd7194ede9.tar.gz
mpd-4a13e19cebb8d72db6e2db9ffb9f9dbd7194ede9.tar.xz
mpd-4a13e19cebb8d72db6e2db9ffb9f9dbd7194ede9.zip
directory: added inline wrappers for accessing children
Some tiny utilities... wrappers like these may become helpful when we introduce locking.
Diffstat (limited to 'src')
-rw-r--r--src/directory.c2
-rw-r--r--src/directory.h14
-rw-r--r--src/update.c10
3 files changed, 19 insertions, 7 deletions
diff --git a/src/directory.c b/src/directory.c
index 305cd5fe3..273515b91 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -79,7 +79,7 @@ directory_get_subdir(struct directory * directory, const char *name)
while (1) {
if (locate)
*locate = '\0';
- if (!(found = dirvec_find(&cur->children, duplicated)))
+ if (!(found = directory_get_child(cur, duplicated)))
break;
assert(cur == found->parent);
cur = found;
diff --git a/src/directory.h b/src/directory.h
index c767366a7..d8f86f50c 100644
--- a/src/directory.h
+++ b/src/directory.h
@@ -62,6 +62,20 @@ static inline const char * directory_get_path(struct directory *dir)
return dir->path;
}
+static inline struct directory *
+directory_get_child(const struct directory *directory, const char *name)
+{
+ return dirvec_find(&directory->children, name);
+}
+
+static inline struct directory *
+directory_new_child(struct directory *directory, const char *name)
+{
+ struct directory *subdir = directory_new(name, directory);
+ dirvec_add(&directory->children, subdir);
+ return subdir;
+}
+
void directory_prune_empty(struct directory *directory);
struct directory *
diff --git a/src/update.c b/src/update.c
index 6e9f1572c..b44d07075 100644
--- a/src/update.c
+++ b/src/update.c
@@ -230,7 +230,7 @@ updateInDirectory(struct directory *directory, const char *name)
return UPDATE_RETURN_UPDATED;
}
} else if (S_ISDIR(st.st_mode)) {
- struct directory *subdir = dirvec_find(&directory->children, name);
+ struct directory *subdir = directory_get_child(directory, name);
if (subdir) {
assert(directory == subdir->parent);
directory_set_stat(subdir, &st);
@@ -318,17 +318,15 @@ static struct directory * addDirectoryPathToDB(const char *utf8path)
if (!parentDirectory)
return NULL;
- if ((directory = dirvec_find(&parentDirectory->children, utf8path))) {
+ if ((directory = directory_get_child(parentDirectory, utf8path))) {
assert(parentDirectory == directory->parent);
} else {
struct stat st;
if (myStat(utf8path, &st) < 0 ||
inodeFoundInParent(parentDirectory, st.st_ino, st.st_dev))
return NULL;
- else {
- directory = directory_new(utf8path, parentDirectory);
- dirvec_add(&parentDirectory->children, directory);
- }
+
+ directory = directory_new_child(parentDirectory, utf8path);
}
/* if we're adding directory paths, make sure to delete filenames