]> granicus.if.org Git - vim/commitdiff
patch 8.2.4566: check for existing buffer in session file may not work v8.2.4566
authorJames Cherti <60946298+jamescherti@users.noreply.github.com>
Mon, 14 Mar 2022 20:24:51 +0000 (20:24 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 14 Mar 2022 20:24:51 +0000 (20:24 +0000)
Problem:    Check for existing buffer in session file does not work for files
            in the home directory.
Solution:   Use fnamemodify(). (James Cherti, closes #9945)  Add a test.

src/session.c
src/testdir/test_mksession.vim
src/version.c

index 68e40db80d5c2bba1a1d9678cf2e8460110e6ecc..fa77f89c8e05038f27519b65db3782b22d334d48 100644 (file)
@@ -385,9 +385,9 @@ put_view(
            // Note, if a buffer for that file already exists, use :badd to
            // edit that buffer, to not lose folding information (:edit resets
            // folds in other buffers)
-           if (fputs("if bufexists(\"", fd) < 0
+           if (fputs("if bufexists(fnamemodify(\"", fd) < 0
                    || ses_fname(fd, wp->w_buffer, flagp, FALSE) == FAIL
-                   || fputs("\") | buffer ", fd) < 0
+                   || fputs("\", \":p\")) | buffer ", fd) < 0
                    || ses_fname(fd, wp->w_buffer, flagp, FALSE) == FAIL
                    || fputs(" | else | edit ", fd) < 0
                    || ses_fname(fd, wp->w_buffer, flagp, FALSE) == FAIL
index 494ac873bbd9cb4febe7af66cb32e521734680d9..2c2737e00692f96c30bb45afe0a6db282c49ba8e 100644 (file)
@@ -245,6 +245,7 @@ func Test_mksession_one_buffer_two_windows()
   let count1 = 0
   let count2 = 0
   let count2buf = 0
+  let bufexists = 0
   for line in lines
     if line =~ 'edit \f*Xtest1$'
       let count1 += 1
@@ -255,10 +256,14 @@ func Test_mksession_one_buffer_two_windows()
     if line =~ 'buffer \f\{-}Xtest2'
       let count2buf += 1
     endif
+    if line =~ 'bufexists(fnamemodify(.*, ":p")'
+      let bufexists += 1
+    endif
   endfor
   call assert_equal(1, count1, 'Xtest1 count')
   call assert_equal(2, count2, 'Xtest2 count')
   call assert_equal(2, count2buf, 'Xtest2 buffer count')
+  call assert_equal(2, bufexists)
 
   close
   bwipe!
index 2ea5965cdc31bcde29ff7658b51be91e632f9a2b..5576f20f9a76425c25964030fb8b81e7621a7dc8 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4566,
 /**/
     4565,
 /**/