mirror of git://git.code.sf.net/p/zsh/code
26774: cd to $HOME on failure in preference to /
This commit is contained in:
parent
9defc9850d
commit
89d979e1bc
|
@ -1,5 +1,7 @@
|
|||
2009-03-24 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* 26774: Src/utils.c: cd to $HOME on failure in preference to /.
|
||||
|
||||
* 26772: Src/glob.c, Src/utils.c, Src/zsh.h, Src/Modules/files.c:
|
||||
more failed cd handling: fix possible runaway series of chdirs;
|
||||
better error handling.
|
||||
|
@ -11480,5 +11482,5 @@
|
|||
|
||||
*****************************************************
|
||||
* This is used by the shell to define $ZSH_PATCHLEVEL
|
||||
* $Revision: 1.4634 $
|
||||
* $Revision: 1.4635 $
|
||||
*****************************************************
|
||||
|
|
22
Src/utils.c
22
Src/utils.c
|
@ -5493,16 +5493,30 @@ lchdir(char const *path, struct dirsav *d, int hard)
|
|||
}
|
||||
if (restoredir(d)) {
|
||||
int restoreerr = errno;
|
||||
int i;
|
||||
/*
|
||||
* Failed to restore the directory.
|
||||
* Just be definite, cd to root and report the result.
|
||||
*/
|
||||
zsfree(pwd);
|
||||
pwd = ztrdup("/");
|
||||
if (chdir(pwd) < 0)
|
||||
for (i = 0; i < 2; i++) {
|
||||
const char *cdest;
|
||||
if (i)
|
||||
cdest = "/";
|
||||
else {
|
||||
if (!home)
|
||||
continue;
|
||||
cdest = home;
|
||||
}
|
||||
zsfree(pwd);
|
||||
pwd = ztrdup(cdest);
|
||||
if (chdir(pwd) == 0)
|
||||
break;
|
||||
}
|
||||
if (i == 2)
|
||||
zerr("lost current directory, failed to cd to /: %e", errno);
|
||||
else
|
||||
zerr("lost current directory: %e: changed to /", restoreerr);
|
||||
zerr("lost current directory: %e: changed to `%s'", restoreerr,
|
||||
pwd);
|
||||
if (d == &ds)
|
||||
zsfree(ds.dirname);
|
||||
#ifdef HAVE_FCHDIR
|
||||
|
|
Loading…
Reference in New Issue