mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 14:08:32 +00:00
vim-patch:8.2.0132: script may be re-used when deleting and creating a new one
Problem: Script may be re-used when deleting and creating a new one.
Solution: When the inode matches, also check the file name.
ca33eb256e
This commit is contained in:
@@ -2161,16 +2161,19 @@ scriptitem_T *get_current_script_id(char_u *fname, sctx_T *ret_sctx)
|
||||
|
||||
bool file_id_ok = os_fileid((char *)fname, &file_id);
|
||||
assert(script_items.ga_len >= 0);
|
||||
for (script_sctx.sc_sid = script_items.ga_len; script_sctx.sc_sid > 0;
|
||||
script_sctx.sc_sid--) {
|
||||
for (script_sctx.sc_sid = script_items.ga_len; script_sctx.sc_sid > 0; script_sctx.sc_sid--) {
|
||||
si = &SCRIPT_ITEM(script_sctx.sc_sid);
|
||||
// Compare dev/ino when possible, it catches symbolic links.
|
||||
// Also compare file names, the inode may change when the file was edited.
|
||||
bool file_id_equal = file_id_ok && si->file_id_valid
|
||||
&& os_fileid_equal(&(si->file_id), &file_id);
|
||||
if (si->sn_name != NULL
|
||||
&& (file_id_equal || FNAMECMP(si->sn_name, fname) == 0)) {
|
||||
break;
|
||||
if (si->sn_name != NULL) {
|
||||
// Compare dev/ino when possible, it catches symbolic links.
|
||||
// Also compare file names, the inode may change when the file was
|
||||
// edited or it may be re-used for another script (esp. in tests).
|
||||
if (file_id_ok && si->file_id_valid && !os_fileid_equal(&(si->file_id), &file_id)) {
|
||||
continue;
|
||||
}
|
||||
if (FNAMECMP(si->sn_name, fname) == 0) {
|
||||
// Found it!
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (script_sctx.sc_sid == 0) {
|
||||
|
@@ -46,3 +46,15 @@ func Test_source_sandbox()
|
||||
bwipe!
|
||||
call delete('Xsourcehello')
|
||||
endfunc
|
||||
|
||||
" When deleting a file and immediately creating a new one the inode may be
|
||||
" recycled. Vim should not recognize it as the same script.
|
||||
func Test_different_script()
|
||||
call ch_logfile('logfile', 'w')
|
||||
call writefile(['let s:var = "asdf"'], 'XoneScript')
|
||||
source XoneScript
|
||||
call delete('XoneScript')
|
||||
call writefile(['let g:var = s:var'], 'XtwoScript')
|
||||
call assert_fails('source XtwoScript', 'E121:')
|
||||
call delete('XtwoScript')
|
||||
endfunc
|
||||
|
Reference in New Issue
Block a user