To: vim-dev@vim.org Subject: Patch 6.1.040 Fcc: outbox From: Bram Moolenaar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.040 Problem: When changing directory for expanding a file name fails there is no error message. Solution: Give an error message for this situation. Don't change directory if we can't return to the original directory. Files: src/diff.c, src/ex_docmd.c, src/globals.h, src/misc1.c, src/os_unix.c *** ../vim61.039/src/diff.c Tue Mar 19 19:38:47 2002 --- src/diff.c Sun Apr 28 18:32:57 2002 *************** *** 780,787 **** /* Temporaraly chdir to /tmp, to avoid patching files in the current * directory when the patch file contains more than one patch. When we * have our own temp dir use that instead, it will be cleaned up when we ! * exit (any .rej files created). */ ! if (mch_dirname(dirbuf, MAXPATHL) != OK) dirbuf[0] = NUL; else { --- 780,788 ---- /* Temporaraly chdir to /tmp, to avoid patching files in the current * directory when the patch file contains more than one patch. When we * have our own temp dir use that instead, it will be cleaned up when we ! * exit (any .rej files created). Don't change directory if we can't ! * return to the current. */ ! if (mch_dirname(dirbuf, MAXPATHL) != OK || mch_chdir(dirbuf) != 0) dirbuf[0] = NUL; else { *************** *** 819,825 **** #ifdef UNIX if (dirbuf[0] != NUL) { ! mch_chdir((char *)dirbuf); shorten_fnames(TRUE); } #endif --- 820,827 ---- #ifdef UNIX if (dirbuf[0] != NUL) { ! if (mch_chdir((char *)dirbuf) != 0) ! EMSG(_(e_prev_dir)); shorten_fnames(TRUE); } #endif *** ../vim61.039/src/ex_docmd.c Tue Apr 9 23:19:52 2002 --- src/ex_docmd.c Sun Apr 28 18:33:41 2002 *************** *** 6689,6695 **** /* * Change to session file's dir. */ ! if (mch_dirname(dirnow, MAXPATHL) == FAIL) *dirnow = NUL; if (*dirnow != NUL && (ssop_flags & SSOP_SESDIR)) { --- 6689,6696 ---- /* * Change to session file's dir. */ ! if (mch_dirname(dirnow, MAXPATHL) == FAIL ! || mch_chdir(dirnow) != 0) *dirnow = NUL; if (*dirnow != NUL && (ssop_flags & SSOP_SESDIR)) { *************** *** 6709,6715 **** if (*dirnow != NUL && ((ssop_flags & SSOP_SESDIR) || ((ssop_flags & SSOP_CURDIR) && globaldir != NULL))) { ! (void)mch_chdir((char *)dirnow); shorten_fnames(TRUE); } } --- 6710,6717 ---- if (*dirnow != NUL && ((ssop_flags & SSOP_SESDIR) || ((ssop_flags & SSOP_CURDIR) && globaldir != NULL))) { ! if (mch_chdir((char *)dirnow) != 0) ! EMSG(_(e_prev_dir)); shorten_fnames(TRUE); } } *** ../vim61.039/src/globals.h Tue Apr 9 23:19:52 2002 --- src/globals.h Tue Apr 23 21:40:11 2002 *************** *** 1122,1127 **** --- 1122,1131 ---- #endif EXTERN char_u e_patnotf2[] INIT(=N_("Pattern not found: %s")); EXTERN char_u e_positive[] INIT(=N_("Argument must be positive")); + #if defined(UNIX) || defined(FEAT_SESSION) + EXTERN char_u e_prev_dir[] INIT(=N_("E459: Cannot go back to previous directory")); + #endif + #ifdef FEAT_QUICKFIX EXTERN char_u e_quickfix[] INIT(=N_("E42: No Errors")); #endif *** ../vim61.039/src/misc1.c Tue Apr 9 20:17:54 2002 --- src/misc1.c Sun Apr 28 18:34:14 2002 *************** *** 2823,2835 **** #ifdef UNIX /* * Change to the directory and get the actual path. This resolves ! * links. */ ! if (mch_dirname(NameBuff, MAXPATHL) == OK) { if (!mch_chdir((char *)var) && mch_dirname(IObuff, IOSIZE) == OK) var = IObuff; ! mch_chdir((char *)NameBuff); } #endif homedir = vim_strsave(var); --- 2823,2836 ---- #ifdef UNIX /* * Change to the directory and get the actual path. This resolves ! * links. Don't do it when we can't return. */ ! if (mch_dirname(NameBuff, MAXPATHL) == OK && mch_chdir(NameBuff) == 0) { if (!mch_chdir((char *)var) && mch_dirname(IObuff, IOSIZE) == OK) var = IObuff; ! if (mch_chdir((char *)NameBuff) != 0) ! EMSG(_(e_prev_dir)); } #endif homedir = vim_strsave(var); *** ../vim61.039/src/os_unix.c Thu Mar 14 22:05:16 2002 --- src/os_unix.c Sun Apr 28 18:37:14 2002 *************** *** 1991,2001 **** } } #endif if ( #ifdef HAVE_FCHDIR fd < 0 && #endif ! mch_dirname(olddir, MAXPATHL) == FAIL) { p = NULL; /* can't get current dir: don't chdir */ retval = FAIL; --- 1991,2005 ---- } } #endif + + /* Only change directory when we are sure we can return to where + * we are now. After doing "su" chdir(".") might not work. */ if ( #ifdef HAVE_FCHDIR fd < 0 && #endif ! (mch_dirname(olddir, MAXPATHL) == FAIL ! || mch_chdir(olddir) != 0)) { p = NULL; /* can't get current dir: don't chdir */ retval = FAIL; *************** *** 2046,2057 **** #ifdef HAVE_FCHDIR if (fd >= 0) { ! fchdir(fd); close(fd); } else #endif ! mch_chdir((char *)olddir); } l = STRLEN(buf); --- 2050,2063 ---- #ifdef HAVE_FCHDIR if (fd >= 0) { ! l = fchdir(fd); close(fd); } else #endif ! l = mch_chdir((char *)olddir); ! if (l != 0) ! EMSG(_(e_prev_dir)); } l = STRLEN(buf); *** ../vim61.039/src/version.c Mon Apr 29 21:53:23 2002 --- src/version.c Mon Apr 29 21:55:38 2002 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 40, /**/ -- Did you ever stop to think... and forget to start again? -- Steven Wright /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\ \\\ Project leader for A-A-P -- http://www.a-a-p.org /// \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///