aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleksander Szczygieł <aelspire@gmail.com>2021-01-20 18:13:06 +0100
committerHarry Jeffery <harry@exec64.co.uk>2021-04-14 15:33:32 +0100
commitff0b802c03b3b783867118415c4d4e6be9403d24 (patch)
tree6659a8fdddeb3b0e558dc45c51e4f8c44800b977 /src
parent478310d0c6bb9610c28c777d4f318fae7272ff12 (diff)
downloadimv-ff0b802c03b3b783867118415c4d4e6be9403d24.tar.gz
Resolve path in imv_navigator_find_path()
All items' pathes are resolved in add_item() so path used in imv_navigator_find_path() should be resolved too. This patch fixes #308
Diffstat (limited to 'src')
-rw-r--r--src/navigator.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/navigator.c b/src/navigator.c
index f2901cf..d62ea52 100644
--- a/src/navigator.c
+++ b/src/navigator.c
@@ -255,15 +255,21 @@ void imv_navigator_remove_all(struct imv_navigator *nav)
ssize_t imv_navigator_find_path(struct imv_navigator *nav, const char *path)
{
- /* first try to match the exact path */
- for (size_t i = 0; i < nav->paths->len; ++i) {
- struct nav_item *item = nav->paths->items[i];
- if (!strcmp(item->path, path)) {
- return (ssize_t)i;
+ char *real_path = realpath(path, NULL);
+ if (real_path) {
+ /* first try to match the exact path if path can be resolved */
+ for (size_t i = 0; i < nav->paths->len; ++i) {
+ struct nav_item *item = nav->paths->items[i];
+ if (!strcmp(item->path, real_path)) {
+ free(real_path);
+ return (ssize_t)i;
+ }
}
+
+ free(real_path);
}
- /* no exact matches, try the final portion of the path */
+ /* no exact matches or path cannot be resolved, try the final portion of the path */
for (size_t i = 0; i < nav->paths->len; ++i) {
struct nav_item *item = nav->paths->items[i];
char *last_sep = strrchr(item->path, '/');