Patch 8.2.1219
Problem:    Symlink not followed if dirname ends in //.
Solution:   Resolve symlink earlier. (Tomáš Janoušek, closes #6454)
Files:      src/memline.c, src/testdir/test_swap.vim


*** ../vim-8.2.1218/src/memline.c       2020-06-12 22:59:07.266097201 +0200
--- src/memline.c       2020-07-15 15:19:21.359366567 +0200
***************
*** 3287,3296 ****
  #endif
  
  /*
!  * Replace line lnum, with buffering, in current buffer.
   *
   * If "copy" is TRUE, make a copy of the line, otherwise the line has been
   * copied to allocated memory already.
   *
   * Check: The caller of this function should probably also call
   * changed_lines(), unless update_screen(NOT_VALID) is used.
--- 3287,3298 ----
  #endif
  
  /*
!  * Replace line "lnum", with buffering, in current buffer.
   *
   * If "copy" is TRUE, make a copy of the line, otherwise the line has been
   * copied to allocated memory already.
+  * If "copy" is FALSE the "line" may be freed to add text properties!
+  * Do not use it after calling ml_replace().
   *
   * Check: The caller of this function should probably also call
   * changed_lines(), unless update_screen(NOT_VALID) is used.
***************
*** 4366,4371 ****
--- 4368,4378 ----
      char_u    *fname_res = fname;
  #ifdef HAVE_READLINK
      char_u    fname_buf[MAXPATHL];
+ 
+     // Expand symlink in the file name, so that we put the swap file with the
+     // actual file instead of with the symlink.
+     if (resolve_symlink(fname, fname_buf) == OK)
+       fname_res = fname_buf;
  #endif
  
  #if defined(UNIX) || defined(MSWIN)  // Need _very_ long file names
***************
*** 4375,4381 ****
      if (after_pathsep(dir_name, s) && len > 1 && s[-1] == s[-2])
      {                        // Ends with '//', Use Full path
        r = NULL;
!       if ((s = make_percent_swname(dir_name, fname)) != NULL)
        {
            r = modname(s, (char_u *)".swp", FALSE);
            vim_free(s);
--- 4382,4388 ----
      if (after_pathsep(dir_name, s) && len > 1 && s[-1] == s[-2])
      {                        // Ends with '//', Use Full path
        r = NULL;
!       if ((s = make_percent_swname(dir_name, fname_res)) != NULL)
        {
            r = modname(s, (char_u *)".swp", FALSE);
            vim_free(s);
***************
*** 4384,4396 ****
      }
  #endif
  
- #ifdef HAVE_READLINK
-     // Expand symlink in the file name, so that we put the swap file with the
-     // actual file instead of with the symlink.
-     if (resolve_symlink(fname, fname_buf) == OK)
-       fname_res = fname_buf;
- #endif
- 
      r = buf_modname(
            (buf->b_p_sn || buf->b_shortname),
            fname_res,
--- 4391,4396 ----
*** ../vim-8.2.1218/src/testdir/test_swap.vim   2020-04-08 21:50:18.876619651 
+0200
--- src/testdir/test_swap.vim   2020-07-15 15:17:53.767686613 +0200
***************
*** 377,380 ****
--- 377,410 ----
    call delete('Xfile1')
  endfunc
  
+ func Test_swap_symlink()
+   if !has("unix")
+     return
+   endif
+ 
+   call writefile(['text'], 'Xtestfile')
+   silent !ln -s -f Xtestfile Xtestlink
+ 
+   set dir=.
+ 
+   " Test that swap file uses the name of the file when editing through a
+   " symbolic link (so that editing the file twice is detected)
+   edit Xtestlink
+   call assert_match('Xtestfile\.swp$', s:swapname())
+   bwipe!
+ 
+   call mkdir('Xswapdir')
+   exe 'set dir=' . getcwd() . '/Xswapdir//'
+ 
+   " Check that this also works when 'directory' ends with '//'
+   edit Xtestlink
+   call assert_match('Xtestfile\.swp$', s:swapname())
+   bwipe!
+ 
+   set dir&
+   call delete('Xtestfile')
+   call delete('Xtestlink')
+   call delete('Xswapdir', 'rf')
+ endfunc
+ 
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.1218/src/version.c       2020-07-15 14:15:47.418627519 +0200
--- src/version.c       2020-07-15 15:20:59.063020623 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1219,
  /**/

-- 
Now it is such a bizarrely improbable coincidence that anything as
mind-bogglingly useful as the Babel fish could have evolved purely by chance
that some thinkers have chosen to see it as a final and clinching proof of the
NON-existence of God.
The argument goes something like this: 'I refuse to prove that I exist,' says
God, 'for proof denies faith, and without faith I am nothing.'
'But,' says Man, 'the Babel fish is a dead giveaway, isn't it?  It could not
have evolved by chance.  It proves you exist, and so therefore, by your own
arguments, you don't.  QED.'
'Oh dear,' says God, 'I hadn't thought of that,' and promptly vanishes in a
puff of logic.
'Oh, that was easy,' says Man, and for an encore goes on to prove that black
is white and gets himself killed on the next pedestrian crossing.
                -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202007151330.06FDUabE3334314%40masaka.moolenaar.net.

Raspunde prin e-mail lui