directory: added inline wrappers for accessing children
Some tiny utilities... wrappers like these may become helpful when we introduce locking.
This commit is contained in:
parent
a5480108f8
commit
cbc0764613
@ -81,7 +81,7 @@ directory_get_directory(struct directory *directory, const char *name)
|
|||||||
while (1) {
|
while (1) {
|
||||||
if (locate)
|
if (locate)
|
||||||
*locate = '\0';
|
*locate = '\0';
|
||||||
if (!(found = dirvec_find(&cur->children, duplicated)))
|
if (!(found = directory_get_child(cur, duplicated)))
|
||||||
break;
|
break;
|
||||||
assert(cur == found->parent);
|
assert(cur == found->parent);
|
||||||
cur = found;
|
cur = found;
|
||||||
|
@ -68,6 +68,20 @@ directory_get_path(struct directory *directory)
|
|||||||
return directory->path;
|
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
|
void
|
||||||
directory_prune_empty(struct directory *directory);
|
directory_prune_empty(struct directory *directory);
|
||||||
|
|
||||||
|
11
src/update.c
11
src/update.c
@ -237,7 +237,7 @@ updateInDirectory(struct directory *directory, const char *name)
|
|||||||
return UPDATE_RETURN_UPDATED;
|
return UPDATE_RETURN_UPDATED;
|
||||||
}
|
}
|
||||||
} else if (S_ISDIR(st.st_mode)) {
|
} 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) {
|
if (subdir) {
|
||||||
assert(directory == subdir->parent);
|
assert(directory == subdir->parent);
|
||||||
directory_set_stat(subdir, &st);
|
directory_set_stat(subdir, &st);
|
||||||
@ -327,17 +327,16 @@ addDirectoryPathToDB(const char *utf8path)
|
|||||||
if (!parentDirectory)
|
if (!parentDirectory)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((directory = dirvec_find(&parentDirectory->children, utf8path))) {
|
if ((directory = directory_get_child(parentDirectory, utf8path))) {
|
||||||
assert(parentDirectory == directory->parent);
|
assert(parentDirectory == directory->parent);
|
||||||
} else {
|
} else {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (myStat(utf8path, &st) < 0 ||
|
if (myStat(utf8path, &st) < 0 ||
|
||||||
inodeFoundInParent(parentDirectory, st.st_ino, st.st_dev))
|
inodeFoundInParent(parentDirectory, st.st_ino, st.st_dev))
|
||||||
return NULL;
|
return NULL;
|
||||||
else {
|
|
||||||
directory = directory_new(utf8path, parentDirectory);
|
directory = directory_new_child(parentDirectory,
|
||||||
dirvec_add(&parentDirectory->children, directory);
|
utf8path);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we're adding directory paths, make sure to delete filenames
|
/* if we're adding directory paths, make sure to delete filenames
|
||||||
|
Loading…
Reference in New Issue
Block a user