Skip to content

Commit 2f9e575

Browse files
committed
patch 8.0.0308: 'runtimepath' not update correctly when using symbolic link
Problem: When using a symbolic link, the package path will not be inserted at the right position in 'runtimepath'. (Dugan Chen, Norio Takagi) Solution: Resolve symbolic links when finding the right position in 'runtimepath'. (Hirohito Higashi)
1 parent 955f198 commit 2f9e575

3 files changed

Lines changed: 55 additions & 13 deletions

File tree

src/ex_cmds2.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,6 +3509,9 @@ add_pack_plugin(char_u *fname, void *cookie)
35093509
size_t afterlen = 0;
35103510
char_u *ffname = fix_fname(fname);
35113511
size_t fname_len;
3512+
char_u *buf = NULL;
3513+
char_u *rtp_ffname;
3514+
int match;
35123515

35133516
if (ffname == NULL)
35143517
return;
@@ -3533,26 +3536,28 @@ add_pack_plugin(char_u *fname, void *cookie)
35333536
/* Find "ffname" in "p_rtp", ignoring '/' vs '\' differences. */
35343537
fname_len = STRLEN(ffname);
35353538
insp = p_rtp;
3536-
for (;;)
3539+
buf = alloc(MAXPATHL);
3540+
if (buf == NULL)
3541+
goto theend;
3542+
while (*insp != NUL)
35373543
{
3538-
if (vim_fnamencmp(insp, ffname, fname_len) == 0)
3539-
break;
3540-
insp = vim_strchr(insp, ',');
3541-
if (insp == NULL)
3544+
copy_option_part(&insp, buf, MAXPATHL, ",");
3545+
add_pathsep(buf);
3546+
rtp_ffname = fix_fname(buf);
3547+
if (rtp_ffname == NULL)
3548+
goto theend;
3549+
match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0;
3550+
vim_free(rtp_ffname);
3551+
if (match)
35423552
break;
3543-
++insp;
35443553
}
35453554

3546-
if (insp == NULL)
3555+
if (*insp == NUL)
35473556
/* not found, append at the end */
35483557
insp = p_rtp + STRLEN(p_rtp);
35493558
else
3550-
{
35513559
/* append after the matching directory. */
3552-
insp += STRLEN(ffname);
3553-
while (*insp != NUL && *insp != ',')
3554-
++insp;
3555-
}
3560+
--insp;
35563561
*p4 = c;
35573562

35583563
/* check if rtp/pack/name/start/name/after exists */
@@ -3562,7 +3567,8 @@ add_pack_plugin(char_u *fname, void *cookie)
35623567

35633568
oldlen = STRLEN(p_rtp);
35643569
addlen = STRLEN(ffname) + 1; /* add one for comma */
3565-
new_rtp = alloc((int)(oldlen + addlen + afterlen + 1)); /* add one for NUL */
3570+
new_rtp = alloc((int)(oldlen + addlen + afterlen + 1));
3571+
/* add one for NUL */
35663572
if (new_rtp == NULL)
35673573
goto theend;
35683574
keep = (int)(insp - p_rtp);
@@ -3616,6 +3622,7 @@ add_pack_plugin(char_u *fname, void *cookie)
36163622
}
36173623

36183624
theend:
3625+
vim_free(buf);
36193626
vim_free(ffname);
36203627
}
36213628

src/testdir/test_packadd.vim

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,39 @@ func Test_packadd_noload()
6767
call assert_equal(new_rtp, &rtp)
6868
endfunc
6969

70+
func Test_packadd_symlink_dir()
71+
if !has('unix')
72+
return
73+
endif
74+
let top2_dir = s:topdir . '/Xdir2'
75+
let real_dir = s:topdir . '/Xsym'
76+
silent !ln -s real_dir top2_dir
77+
let &rtp = top2_dir . ',' . top2_dir . '/after'
78+
let &packpath = &rtp
79+
80+
let s:plugdir = top2_dir . '/pack/mine/opt/mytest'
81+
call mkdir(s:plugdir . '/plugin', 'p')
82+
83+
exe 'split ' . s:plugdir . '/plugin/test.vim'
84+
call setline(1, 'let g:plugin_works = 44')
85+
wq
86+
let g:plugin_works = 0
87+
88+
packadd mytest
89+
90+
" Must have been inserted in the middle, not at the end
91+
call assert_true(&rtp =~ '/pack/mine/opt/mytest,')
92+
call assert_equal(44, g:plugin_works)
93+
94+
" No change when doing it again.
95+
let rtp_before = &rtp
96+
packadd mytest
97+
call assert_equal(rtp_before, &rtp)
98+
99+
set rtp&
100+
let rtp = &rtp
101+
endfunc
102+
70103
" Check command-line completion for 'packadd'
71104
func Test_packadd_completion()
72105
let optdir1 = &packpath . '/pack/mine/opt'

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
308,
767769
/**/
768770
307,
769771
/**/

0 commit comments

Comments
 (0)