vim-patch:8.0.1734: package directory not added to 'rtp' if prefix matches

Problem:    Package directory not added to 'rtp' if prefix matches.
Solution:   Check the match is a full match. (Ozaki Kiichi, closes vim/vim#2817)
            Also handle different ways of spelling a path.
f98a39ca57
This commit is contained in:
James McCoy
2018-12-29 01:15:59 -05:00
parent e09fb6ee53
commit 91f40ff284
2 changed files with 27 additions and 4 deletions

View File

@@ -2683,12 +2683,26 @@ static int APP_BOTH;
static void add_pack_plugin(char_u *fname, void *cookie) static void add_pack_plugin(char_u *fname, void *cookie)
{ {
if (cookie != &APP_LOAD && strstr((char *)p_rtp, (char *)fname) == NULL) { if (cookie != &APP_LOAD) {
char *buf = xmalloc(MAXPATHL);
bool found = false;
const char *p = (const char *)p_rtp;
while (*p != NUL) {
copy_option_part((char_u **)&p, (char_u *)buf, MAXPATHL, ",");
if (path_fnamecmp(buf, (char *)fname) == 0) {
found = true;
break;
}
}
xfree(buf);
if (!found) {
// directory is not yet in 'runtimepath', add it // directory is not yet in 'runtimepath', add it
if (add_pack_dir_to_rtp(fname) == FAIL) { if (add_pack_dir_to_rtp(fname) == FAIL) {
return; return;
} }
} }
}
if (cookie != &APP_ADD_DIR) { if (cookie != &APP_ADD_DIR) {
load_pack_plugin(fname); load_pack_plugin(fname);

View File

@@ -57,6 +57,15 @@ describe('packadd', function()
call assert_match(Escape(s:plugdir) . '\($\|,\)', &rtp) call assert_match(Escape(s:plugdir) . '\($\|,\)', &rtp)
call assert_match(Escape(expand(s:plugdir . '/after$')), &rtp) call assert_match(Escape(expand(s:plugdir . '/after$')), &rtp)
" NOTE: '/.../opt/myte' forwardly matches with '/.../opt/mytest'
call mkdir(fnamemodify(s:plugdir, ':h') . '/myte', 'p')
let rtp = &rtp
packadd myte
" Check the path of 'myte' is added
call assert_true(len(&rtp) > len(rtp))
call assert_match(Escape(s:plugdir) . '\($\|,\)', &rtp)
" Check exception " Check exception
call assert_fails("packadd directorynotfound", 'E919:') call assert_fails("packadd directorynotfound", 'E919:')
call assert_fails("packadd", 'E471:') call assert_fails("packadd", 'E471:')