summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun <engineerarun@gmail.com>2023-11-25 18:34:01 +0530
committerGitHub <noreply@github.com>2023-11-25 18:34:01 +0530
commit404eed5fc79db79a60db98de6a1f231849543b22 (patch)
tree0ba254b8556a23b8c3ef49b3b223e9aefc0d5bcb
parent485079d3ec20ecba08fc964d2947fcd612f4c09f (diff)
parent9aaf9491ad6a144ad096bcde9a5605c628c83e42 (diff)
Merge pull request #1773 from 7ocb/handle-link-by-readlink-not-realpath-mk2
When handling bookmark, use readlink, not realpath
-rw-r--r--src/nnn.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/nnn.c b/src/nnn.c
index d8e33260..07dcba60 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -1310,6 +1310,18 @@ static char *abspath(const char *filepath, char *cwd, char *buf)
return resolved_path;
}
+/* finds abspath of link pointed by filepath, taking cwd into account */
+static char *bmtarget(const char *filepath, char *cwd, char *buf)
+{
+ char target[PATH_MAX + 1];
+ ssize_t n = readlink(filepath, target, PATH_MAX);
+ if (n != -1) {
+ target[n] = '\0';
+ return abspath(target, cwd, buf);
+ }
+ return NULL;
+}
+
/* wraps the argument in single quotes so it can be safely fed to shell */
static bool shell_escape(char *output, size_t outlen, const char *s)
{
@@ -7053,7 +7065,7 @@ nochange:
pent = &pdents[cur];
if (!g_state.selbm || !(S_ISLNK(pent->mode) &&
- realpath(pent->name, newpath) &&
+ bmtarget(pent->name, path, newpath) &&
xstrsncpy(path, lastdir, PATH_MAX)))
mkpath(path, pent->name, newpath);
g_state.selbm = 0;