]> Sergey Matveev's repositories - nnn.git/commitdiff
Merge pull request #1770 from 7ocb/pass-path-to-abspath
authorArun <engineerarun@gmail.com>
Sat, 25 Nov 2023 13:06:52 +0000 (18:36 +0530)
committerGitHub <noreply@github.com>
Sat, 25 Nov 2023 13:06:52 +0000 (18:36 +0530)
When handling SEL_NEW pass `path` to `abspath` call

1  2 
src/nnn.c

diff --combined src/nnn.c
index 07dcba608b4c16cfa21e9955b1eb691ac0c83a23,6c90377f9bbffa252233f71369809f5a7e5c62e8..dbc64197fd50e5bfa15e0313492f6dc1a865ca73
+++ b/src/nnn.c
@@@ -1310,18 -1310,6 +1310,18 @@@ static char *abspath(const char *filepa
        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)
  {
@@@ -5172,7 -5160,6 +5172,7 @@@ static void show_help(const char *path
                  "cT  Set time type%110  Lock\n"
                 "b^L  Redraw%18?  Help, conf\n"
        };
 +      char help_buf[1<<11]; // if editing helpstr, ensure this has enough space to decode it
  
        int fd = create_tmp_file();
        if (fd == -1)
                get_output(prog, NULL, NULL, fd, FALSE);
  
        bool hex = true;
 -      char *w = g_buf;
 +      char *w = help_buf;
        const char *end = helpstr + (sizeof helpstr - 1);
        for (const char *s = helpstr; s < end; ++s) {
                if (hex) {
                }
                hex = *s == '\n';
        }
 -      if (write(fd, g_buf, w - g_buf)) {} // silence warning
 +      ssize_t res = write(fd, help_buf, w - help_buf);
 +      (void)res; // silence warning
  
        dprintf(fd, "\nLOCATIONS\n");
        for (uchar_t i = 0; i < CTX_MAX; ++i)
@@@ -7065,7 -7051,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;
                        }
  
                        if (!(r == 's' || r == 'h')) {
-                               tmp = abspath(tmp, NULL, newpath);
+                               tmp = abspath(tmp, path, newpath);
                                if (!tmp) {
                                        printwarn(&presel);
                                        goto nochange;