mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Significantly improve accuracy of error reporting in the cd builtin
darcs-hash:20070920172928-75c98-826cd86e1c33e1f6c746227655e340a6bb459f30.gz
This commit is contained in:
parent
64933d31a6
commit
3b39b1fa03
2 changed files with 57 additions and 6 deletions
46
builtin.c
46
builtin.c
|
@ -2318,25 +2318,61 @@ static int builtin_cd( wchar_t **argv )
|
|||
|
||||
if( !dir )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: '%ls' is not a directory or you do not have permission to enter it\n" ),
|
||||
if( errno == ENOTDIR )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: '%ls' is not a directory\n" ),
|
||||
argv[0],
|
||||
dir_in );
|
||||
}
|
||||
else if( errno == ENOENT )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: The directory '%ls' does not exist\n" ),
|
||||
argv[0],
|
||||
dir_in );
|
||||
|
||||
} else {
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: Unknown error trying to locate directory '%ls'\n" ),
|
||||
argv[0],
|
||||
dir_in );
|
||||
|
||||
}
|
||||
|
||||
|
||||
if( !is_interactive )
|
||||
{
|
||||
sb_append2( sb_err,
|
||||
parser_current_line(),
|
||||
(void *)0 );
|
||||
parser_current_line(),
|
||||
(void *)0 );
|
||||
}
|
||||
|
||||
res = 1;
|
||||
}
|
||||
else if( wchdir( dir ) != 0 )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
struct stat buffer;
|
||||
int status;
|
||||
|
||||
status = wstat( dir, &buffer );
|
||||
if( !status && S_ISDIR(buffer.st_mode))
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: Permission denied: '%ls'\n" ),
|
||||
argv[0],
|
||||
dir );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: '%ls' is not a directory\n" ),
|
||||
argv[0],
|
||||
dir );
|
||||
}
|
||||
|
||||
if( !is_interactive )
|
||||
{
|
||||
sb_append2( sb_err,
|
||||
|
|
17
path.c
17
path.c
|
@ -137,7 +137,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
|
|||
wchar_t *path_get_cdpath( void *context, wchar_t *dir )
|
||||
{
|
||||
wchar_t *res = 0;
|
||||
|
||||
int err = ENOENT;
|
||||
if( !dir )
|
||||
return 0;
|
||||
|
||||
|
@ -151,6 +151,11 @@ wchar_t *path_get_cdpath( void *context, wchar_t *dir )
|
|||
{
|
||||
res = halloc_wcsdup( context, dir );
|
||||
}
|
||||
else
|
||||
{
|
||||
err = ENOTDIR;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -207,11 +212,21 @@ wchar_t *path_get_cdpath( void *context, wchar_t *dir )
|
|||
halloc_register( context, whole_path );
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = ENOTDIR;
|
||||
}
|
||||
}
|
||||
free( whole_path );
|
||||
}
|
||||
free( path_cpy );
|
||||
}
|
||||
|
||||
if( !res )
|
||||
{
|
||||
errno = err;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue