aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-01-29 14:42:28 +0100
committerMax Kellermann <max@duempel.org>2012-01-29 14:42:28 +0100
commitf20689519dfb9a4fffa3fbe4862ff12fb17639eb (patch)
tree0ef361aecfbf9da77a813d4a9006b3ba8ed7fb9a /src
parentee9c460f7491fa93bfcbb46e7abf4b44f8f87580 (diff)
downloadmpd-f20689519dfb9a4fffa3fbe4862ff12fb17639eb.tar.gz
mpd-f20689519dfb9a4fffa3fbe4862ff12fb17639eb.tar.xz
mpd-f20689519dfb9a4fffa3fbe4862ff12fb17639eb.zip
directory: fix deep path lookup
This commit fixes a major regression in directory_lookup_directory(), which broke the deep lookup of directories.
Diffstat (limited to '')
-rw-r--r--src/directory.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/directory.c b/src/directory.c
index f8a545b9c..82bacc932 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -149,34 +149,32 @@ directory_prune_empty(struct directory *directory)
struct directory *
directory_lookup_directory(struct directory *directory, const char *uri)
{
- struct directory *cur = directory;
- struct directory *found = NULL;
- char *duplicated;
- char *locate;
-
assert(uri != NULL);
if (isRootDirectory(uri))
return directory;
- duplicated = g_strdup(uri);
- locate = strchr(duplicated, '/');
+ char *duplicated = g_strdup(uri), *name = duplicated;
while (1) {
- if (locate)
- *locate = '\0';
- if (!(found = directory_get_child(cur, duplicated)))
+ char *slash = strchr(name, '/');
+ if (slash == name) {
+ directory = NULL;
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;
- *locate = '/';
- locate = strchr(locate + 1, '/');
+
+ name = slash + 1;
}
g_free(duplicated);
- return found;
+ return directory;
}
void