Skip to content

Commit

Permalink
Merge pull request jarun#1773 from 7ocb/handle-link-by-readlink-not-r…
Browse files Browse the repository at this point in the history
…ealpath-mk2

When handling bookmark, use readlink, not realpath
  • Loading branch information
jarun authored Nov 25, 2023
2 parents 485079d + 9aaf949 commit 404eed5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/nnn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -7053,7 +7065,7 @@ static bool browse(char *ipath, const char *session, int pkey)

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;
Expand Down

0 comments on commit 404eed5

Please sign in to comment.