comparison src/scriptfile.c @ 29828:6b7020f3d856 v9.0.0253

patch 9.0.0253: a symlink to an autoload script results in two entries Commit: https://github.com/vim/vim/commit/753885b6c5b9021184daa94d32fd8bf025f1b488 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 24 16:30:36 2022 +0100 patch 9.0.0253: a symlink to an autoload script results in two entries Problem: A symlink to an autoload script results in two entries in the list of scripts, items expected in one are actually in the other. Solution: Have one script item refer to the actually sourced one. (closes #10960)
author Bram Moolenaar <Bram@vim.org>
date Wed, 24 Aug 2022 17:45:03 +0200
parents 8ebfea14d9bb
children 4a549427855d
comparison
equal deleted inserted replaced
29827:db296237ca1d 29828:6b7020f3d856
1355 exarg_T *eap, 1355 exarg_T *eap,
1356 int clearvars UNUSED) 1356 int clearvars UNUSED)
1357 { 1357 {
1358 source_cookie_T cookie; 1358 source_cookie_T cookie;
1359 char_u *p; 1359 char_u *p;
1360 char_u *fname_not_fixed = NULL;
1360 char_u *fname_exp; 1361 char_u *fname_exp;
1361 char_u *firstline = NULL; 1362 char_u *firstline = NULL;
1362 int retval = FAIL; 1363 int retval = FAIL;
1363 sctx_T save_current_sctx; 1364 sctx_T save_current_sctx;
1364 #ifdef FEAT_EVAL 1365 #ifdef FEAT_EVAL
1387 if (fname_exp == NULL) 1388 if (fname_exp == NULL)
1388 return FAIL; 1389 return FAIL;
1389 } 1390 }
1390 else 1391 else
1391 { 1392 {
1392 p = expand_env_save(fname); 1393 fname_not_fixed = expand_env_save(fname);
1393 if (p == NULL) 1394 if (fname_not_fixed == NULL)
1394 return retval; 1395 goto theend;
1395 fname_exp = fix_fname(p); 1396 fname_exp = fix_fname(fname_not_fixed);
1396 vim_free(p);
1397 if (fname_exp == NULL) 1397 if (fname_exp == NULL)
1398 return retval; 1398 goto theend;
1399 if (mch_isdir(fname_exp)) 1399 if (mch_isdir(fname_exp))
1400 { 1400 {
1401 smsg(_("Cannot source a directory: \"%s\""), fname); 1401 smsg(_("Cannot source a directory: \"%s\""), fname);
1402 goto theend; 1402 goto theend;
1403 } 1403 }
1600 else 1600 else
1601 { 1601 {
1602 int error = OK; 1602 int error = OK;
1603 1603
1604 // It's new, generate a new SID and initialize the scriptitem. 1604 // It's new, generate a new SID and initialize the scriptitem.
1605 current_sctx.sc_sid = get_new_scriptitem(&error); 1605 sid = get_new_scriptitem(&error);
1606 current_sctx.sc_sid = sid;
1606 if (error == FAIL) 1607 if (error == FAIL)
1607 goto almosttheend; 1608 goto almosttheend;
1608 si = SCRIPT_ITEM(current_sctx.sc_sid); 1609 si = SCRIPT_ITEM(sid);
1609 si->sn_name = fname_exp; 1610 si->sn_name = fname_exp;
1610 fname_exp = vim_strsave(si->sn_name); // used for autocmd 1611 fname_exp = vim_strsave(si->sn_name); // used for autocmd
1611 if (ret_sid != NULL) 1612 if (ret_sid != NULL)
1612 *ret_sid = current_sctx.sc_sid; 1613 *ret_sid = sid;
1613 1614
1614 // Remember the "is_vimrc" flag for when the file is sourced again. 1615 // Remember the "is_vimrc" flag for when the file is sourced again.
1615 si->sn_is_vimrc = is_vimrc; 1616 si->sn_is_vimrc = is_vimrc;
1616 } 1617 }
1617 1618
1666 1667
1667 #ifdef FEAT_PROFILE 1668 #ifdef FEAT_PROFILE
1668 if (do_profiling == PROF_YES) 1669 if (do_profiling == PROF_YES)
1669 { 1670 {
1670 // Get "si" again, "script_items" may have been reallocated. 1671 // Get "si" again, "script_items" may have been reallocated.
1671 si = SCRIPT_ITEM(current_sctx.sc_sid); 1672 si = SCRIPT_ITEM(sid);
1672 if (si->sn_prof_on) 1673 if (si->sn_prof_on)
1673 { 1674 {
1674 profile_end(&si->sn_pr_start); 1675 profile_end(&si->sn_pr_start);
1675 profile_sub_wait(&wait_start, &si->sn_pr_start); 1676 profile_sub_wait(&wait_start, &si->sn_pr_start);
1676 profile_add(&si->sn_pr_total, &si->sn_pr_start); 1677 profile_add(&si->sn_pr_total, &si->sn_pr_start);
1717 #ifdef FEAT_EVAL 1718 #ifdef FEAT_EVAL
1718 almosttheend: 1719 almosttheend:
1719 // If "sn_save_cpo" is set that means we encountered "vim9script": restore 1720 // If "sn_save_cpo" is set that means we encountered "vim9script": restore
1720 // 'cpoptions', unless in the main .vimrc file. 1721 // 'cpoptions', unless in the main .vimrc file.
1721 // Get "si" again, "script_items" may have been reallocated. 1722 // Get "si" again, "script_items" may have been reallocated.
1722 si = SCRIPT_ITEM(current_sctx.sc_sid); 1723 si = SCRIPT_ITEM(sid);
1723 if (si->sn_save_cpo != NULL && si->sn_is_vimrc == DOSO_NONE) 1724 if (si->sn_save_cpo != NULL && si->sn_is_vimrc == DOSO_NONE)
1724 { 1725 {
1725 if (STRCMP(p_cpo, CPO_VIM) != 0) 1726 if (STRCMP(p_cpo, CPO_VIM) != 0)
1726 { 1727 {
1727 char_u *f; 1728 char_u *f;
1772 1773
1773 if (trigger_source_post) 1774 if (trigger_source_post)
1774 apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp, FALSE, curbuf); 1775 apply_autocmds(EVENT_SOURCEPOST, fname_exp, fname_exp, FALSE, curbuf);
1775 1776
1776 theend: 1777 theend:
1778 if (sid > 0 && ret_sid != NULL
1779 && fname_not_fixed != NULL && fname_exp != NULL)
1780 {
1781 int not_fixed_sid = find_script_by_name(fname_not_fixed);
1782
1783 // If "fname_not_fixed" is a symlink then we source the linked file.
1784 // If the original name is in the script list we add the ID of the
1785 // script that was actually sourced.
1786 if (SCRIPT_ID_VALID(not_fixed_sid) && not_fixed_sid != sid)
1787 SCRIPT_ITEM(not_fixed_sid)->sn_sourced_sid = sid;
1788 }
1789
1790 vim_free(fname_not_fixed);
1777 vim_free(fname_exp); 1791 vim_free(fname_exp);
1778 sticky_cmdmod_flags = save_sticky_cmdmod_flags; 1792 sticky_cmdmod_flags = save_sticky_cmdmod_flags;
1779 #ifdef FEAT_EVAL 1793 #ifdef FEAT_EVAL
1780 estack_compiling = save_estack_compiling; 1794 estack_compiling = save_estack_compiling;
1781 #endif 1795 #endif
1785 int 1799 int
1786 do_source( 1800 do_source(
1787 char_u *fname, 1801 char_u *fname,
1788 int check_other, // check for .vimrc and _vimrc 1802 int check_other, // check for .vimrc and _vimrc
1789 int is_vimrc, // DOSO_ value 1803 int is_vimrc, // DOSO_ value
1790 int *ret_sid UNUSED) 1804 int *ret_sid)
1791 { 1805 {
1792 return do_source_ext(fname, check_other, is_vimrc, ret_sid, NULL, FALSE); 1806 return do_source_ext(fname, check_other, is_vimrc, ret_sid, NULL, FALSE);
1793 } 1807 }
1794 1808
1795 1809
1826 { 1840 {
1827 scriptitem_T *si = SCRIPT_ITEM(i); 1841 scriptitem_T *si = SCRIPT_ITEM(i);
1828 1842
1829 if (si->sn_name != NULL) 1843 if (si->sn_name != NULL)
1830 { 1844 {
1845 char sourced_buf[20];
1846
1831 home_replace(NULL, si->sn_name, NameBuff, MAXPATHL, TRUE); 1847 home_replace(NULL, si->sn_name, NameBuff, MAXPATHL, TRUE);
1832 vim_snprintf((char *)IObuff, IOSIZE, "%3d%s: %s", 1848 if (si->sn_sourced_sid > 0)
1849 vim_snprintf(sourced_buf, 20, "->%d", si->sn_sourced_sid);
1850 else
1851 sourced_buf[0] = NUL;
1852 vim_snprintf((char *)IObuff, IOSIZE, "%3d%s%s: %s",
1833 i, 1853 i,
1854 sourced_buf,
1834 si->sn_state == SN_STATE_NOT_LOADED ? " A" : "", 1855 si->sn_state == SN_STATE_NOT_LOADED ? " A" : "",
1835 NameBuff); 1856 NameBuff);
1836 if (!message_filtered(IObuff)) 1857 if (!message_filtered(IObuff))
1837 { 1858 {
1838 msg_putchar('\n'); 1859 msg_putchar('\n');
1944 1965
1945 if ((d = dict_alloc()) == NULL 1966 if ((d = dict_alloc()) == NULL
1946 || list_append_dict(l, d) == FAIL 1967 || list_append_dict(l, d) == FAIL
1947 || dict_add_string(d, "name", si->sn_name) == FAIL 1968 || dict_add_string(d, "name", si->sn_name) == FAIL
1948 || dict_add_number(d, "sid", i) == FAIL 1969 || dict_add_number(d, "sid", i) == FAIL
1970 || dict_add_number(d, "sourced", si->sn_sourced_sid) == FAIL
1949 || dict_add_bool(d, "autoload", 1971 || dict_add_bool(d, "autoload",
1950 si->sn_state == SN_STATE_NOT_LOADED) == FAIL) 1972 si->sn_state == SN_STATE_NOT_LOADED) == FAIL)
1951 return; 1973 return;
1952 } 1974 }
1953 } 1975 }