directory: fix deep path lookup
This commit fixes a major regression in directory_lookup_directory(), which broke the deep lookup of directories.
This commit is contained in:
parent
ee9c460f74
commit
f20689519d
@ -149,34 +149,32 @@ directory_prune_empty(struct directory *directory)
|
|||||||
struct directory *
|
struct directory *
|
||||||
directory_lookup_directory(struct directory *directory, const char *uri)
|
directory_lookup_directory(struct directory *directory, const char *uri)
|
||||||
{
|
{
|
||||||
struct directory *cur = directory;
|
|
||||||
struct directory *found = NULL;
|
|
||||||
char *duplicated;
|
|
||||||
char *locate;
|
|
||||||
|
|
||||||
assert(uri != NULL);
|
assert(uri != NULL);
|
||||||
|
|
||||||
if (isRootDirectory(uri))
|
if (isRootDirectory(uri))
|
||||||
return directory;
|
return directory;
|
||||||
|
|
||||||
duplicated = g_strdup(uri);
|
char *duplicated = g_strdup(uri), *name = duplicated;
|
||||||
locate = strchr(duplicated, '/');
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (locate)
|
char *slash = strchr(name, '/');
|
||||||
*locate = '\0';
|
if (slash == name) {
|
||||||
if (!(found = directory_get_child(cur, duplicated)))
|
directory = NULL;
|
||||||
break;
|
break;
|
||||||
assert(cur == found->parent);
|
}
|
||||||
cur = found;
|
|
||||||
if (!locate)
|
if (slash != NULL)
|
||||||
|
*slash = '\0';
|
||||||
|
|
||||||
|
directory = directory_get_child(directory, name);
|
||||||
|
if (directory == NULL || slash == NULL)
|
||||||
break;
|
break;
|
||||||
*locate = '/';
|
|
||||||
locate = strchr(locate + 1, '/');
|
name = slash + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(duplicated);
|
g_free(duplicated);
|
||||||
|
|
||||||
return found;
|
return directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user