comparison src/misc2.c @ 15184:90ab2d3ce11d v8.1.0602

patch 8.1.0602: DirChanged is also triggered when directory didn't change commit https://github.com/vim/vim/commit/2caad3fbbdbf1486a176c9f6bfbc3d9be90e09f7 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Dec 16 15:38:02 2018 +0100 patch 8.1.0602: DirChanged is also triggered when directory didn't change Problem: DirChanged is also triggered when the directory didn't change. (Daniel Hahler) Solution: Compare the current with the new directory. (closes #3697)
author Bram Moolenaar <Bram@vim.org>
date Sun, 16 Dec 2018 15:45:06 +0100
parents ec67c6b8ef12
children 2d8c31ae1e24
comparison
equal deleted inserted replaced
15183:c43fefb0ab38 15184:90ab2d3ce11d
3388 * Change to a file's directory. 3388 * Change to a file's directory.
3389 * Caller must call shorten_fnames()! 3389 * Caller must call shorten_fnames()!
3390 * Return OK or FAIL. 3390 * Return OK or FAIL.
3391 */ 3391 */
3392 int 3392 int
3393 vim_chdirfile(char_u *fname, char *trigger_autocmd UNUSED) 3393 vim_chdirfile(char_u *fname, char *trigger_autocmd)
3394 { 3394 {
3395 char_u dir[MAXPATHL]; 3395 char_u old_dir[MAXPATHL];
3396 char_u new_dir[MAXPATHL];
3396 int res; 3397 int res;
3397 3398
3398 vim_strncpy(dir, fname, MAXPATHL - 1); 3399 if (mch_dirname(old_dir, MAXPATHL) != OK)
3399 *gettail_sep(dir) = NUL; 3400 *old_dir = NUL;
3400 res = mch_chdir((char *)dir) == 0 ? OK : FAIL; 3401
3401 if (res == OK && trigger_autocmd != NULL) 3402 vim_strncpy(new_dir, fname, MAXPATHL - 1);
3402 apply_autocmds(EVENT_DIRCHANGED, (char_u *)trigger_autocmd, 3403 *gettail_sep(new_dir) = NUL;
3403 dir, FALSE, curbuf); 3404
3405 if (STRCMP(old_dir, new_dir) == 0)
3406 // nothing to do
3407 res = OK;
3408 else
3409 {
3410 res = mch_chdir((char *)new_dir) == 0 ? OK : FAIL;
3411
3412 if (res == OK && trigger_autocmd != NULL)
3413 apply_autocmds(EVENT_DIRCHANGED, (char_u *)trigger_autocmd,
3414 new_dir, FALSE, curbuf);
3415 }
3404 return res; 3416 return res;
3405 } 3417 }
3406 #endif 3418 #endif
3407 3419
3408 #if defined(STAT_IGNORES_SLASH) || defined(PROTO) 3420 #if defined(STAT_IGNORES_SLASH) || defined(PROTO)