diff options
author | Max Kellermann <max@duempel.org> | 2008-10-09 15:34:07 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-09 15:34:07 +0200 |
commit | cbc076461371fca57749191fb323cf75b43d9544 (patch) | |
tree | cbeb77d790debcf46ad4ba7aaabaa3597927a06b | |
parent | a5480108f8c834a1db3b5c4f30a7dd7e9569776e (diff) | |
download | mpd-cbc076461371fca57749191fb323cf75b43d9544.tar.gz mpd-cbc076461371fca57749191fb323cf75b43d9544.tar.xz mpd-cbc076461371fca57749191fb323cf75b43d9544.zip |
directory: added inline wrappers for accessing children
Some tiny utilities... wrappers like these may become helpful when we
introduce locking.
Diffstat (limited to '')
-rw-r--r-- | src/directory.c | 2 | ||||
-rw-r--r-- | src/directory.h | 14 | ||||
-rw-r--r-- | src/update.c | 11 |
3 files changed, 20 insertions, 7 deletions
diff --git a/src/directory.c b/src/directory.c index 3a5e5955d..e63310026 100644 --- a/src/directory.c +++ b/src/directory.c @@ -81,7 +81,7 @@ directory_get_directory(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 14bda5b58..9dd064ef7 100644 --- a/src/directory.h +++ b/src/directory.h @@ -68,6 +68,20 @@ directory_get_path(struct directory *directory) return directory->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); diff --git a/src/update.c b/src/update.c index 1731f947d..e24702749 100644 --- a/src/update.c +++ b/src/update.c @@ -237,7 +237,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); @@ -327,17 +327,16 @@ 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 |