Hi Bram and list,
How to reproduce:
- Symbolic link to ~/.vim
$ mkdir -p ~/sample/.vim/pack/dist/opt/bar/plugin/
$ ln -s ~/sample/.vim/ ~/
- Run vanilla Vim and set 'runtimepath'
$ vim -Nu NONE +"set rtp=~/.vim,~/.vim/after"
- Adding package 'bar'
:packadd bar
- Confirm 'rtp'
:echo rtp
Expect value:
runtimepath=~/.vim,~/sample/.vim/pack/dist/opt/bar,~/.vim/after
Actual value:
runtimepath=~/.vim,~/.vim/after,~/sample/.vim/pack/dist/opt/bar
'~/sample/.vim/pack/dist/opt/bar' should be added immediately after '~/.vim'.
Because '~/sample/.vim/pack/dist/opt/bar' is included in '~/.vim'.
REMARKS:
This phenomenon does not occur if ~/.vim is not a symbolic link.
Investigation result:
in add_pack_plugin(),
3510 char_u *ffname = fix_fname(fname);
...
3535 insp = p_rtp;
3536 for (;;)
3537 {
3538 if (vim_fnamencmp(insp, ffname, fname_len) == 0)
3539 break;
3540 insp = vim_strchr(insp, ',');
3541 if (insp == NULL)
3542 break;
3543 ++insp;
3544 }
Although fix_fname() returns the path that resolved the symbolic link, each
'rtp' directory does not do it.
I wrote a patch contains test.
Check it please.
NOTE:
This issue was reported by Norio Takagi.
https://github.com/vim-jp/issues/issues/1022 (in Japanese)
--
Best regards,
Hirohito Higashi (a.k.a. h_east)
--
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c
index 59dc4d5..636e7f3 100644
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -3509,6 +3509,8 @@ add_pack_plugin(char_u *fname, void *cookie)
size_t afterlen = 0;
char_u *ffname = fix_fname(fname);
size_t fname_len;
+ char_u *buf;
+ char_u *rtp_ffname;
if (ffname == NULL)
return;
@@ -3533,26 +3535,31 @@ add_pack_plugin(char_u *fname, void *cookie)
/* Find "ffname" in "p_rtp", ignoring '/' vs '\' differences. */
fname_len = STRLEN(ffname);
insp = p_rtp;
- for (;;)
+ buf = alloc(MAXPATHL);
+ if (buf == NULL)
+ goto theend;
+ while (*insp != NUL)
{
- if (vim_fnamencmp(insp, ffname, fname_len) == 0)
- break;
- insp = vim_strchr(insp, ',');
- if (insp == NULL)
+ copy_option_part(&insp, buf, MAXPATHL, ",");
+ add_pathsep(buf);
+ rtp_ffname = fix_fname(buf);
+ if (rtp_ffname == NULL)
+ {
+ vim_free(buf);
+ goto theend;
+ }
+ if (vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0)
break;
- ++insp;
}
+ vim_free(buf);
+ vim_free(rtp_ffname);
- if (insp == NULL)
+ if (*insp == NUL)
/* not found, append at the end */
insp = p_rtp + STRLEN(p_rtp);
else
- {
/* append after the matching directory. */
- insp += STRLEN(ffname);
- while (*insp != NUL && *insp != ',')
- ++insp;
- }
+ --insp;
*p4 = c;
/* check if rtp/pack/name/start/name/after exists */
diff --git a/src/testdir/test_packadd.vim b/src/testdir/test_packadd.vim
index eca1560..0a4d829 100644
--- a/src/testdir/test_packadd.vim
+++ b/src/testdir/test_packadd.vim
@@ -67,6 +67,34 @@ func Test_packadd_noload()
call assert_equal(new_rtp, &rtp)
endfunc
+func Test_packadd_symlink_dir()
+ if !has('unix')
+ return
+ endif
+ let top2_dir = s:topdir . '/Xdir2'
+ let real_dir = s:topdir . '/Xsym'
+ silent !ln -s real_dir top2_dir
+ let &rtp = top2_dir . ',' . top2_dir . '/after'
+ let &packpath = &rtp
+
+ let s:plugdir = top2_dir . '/pack/mine/opt/mytest'
+ call mkdir(s:plugdir . '/plugin', 'p')
+
+ exe 'split ' . s:plugdir . '/plugin/test.vim'
+ call setline(1, 'let g:plugin_works = 44')
+ wq
+ let g:plugin_works = 0
+
+ packadd mytest
+
+ " Not a last
+ call assert_true(&rtp =~ '/pack/mine/opt/mytest,')
+ call assert_equal(44, g:plugin_works)
+
+ set rtp&
+ let rtp = &rtp
+endfunc
+
" Check command-line completion for 'packadd'
func Test_packadd_completion()
let optdir1 = &packpath . '/pack/mine/opt'
@@ -236,3 +264,5 @@ func Test_runtime()
runtime! ALL extra/bar.vim
call assert_equal('runstartopt', g:sequence)
endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab