From 3b39b1fa0302dcb0757b060a4255b84bee83d540 Mon Sep 17 00:00:00 2001 From: liljencrantz Date: Fri, 21 Sep 2007 03:29:28 +1000 Subject: [PATCH] Significantly improve accuracy of error reporting in the cd builtin darcs-hash:20070920172928-75c98-826cd86e1c33e1f6c746227655e340a6bb459f30.gz --- builtin.c | 46 +++++++++++++++++++++++++++++++++++++++++----- path.c | 17 ++++++++++++++++- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/builtin.c b/builtin.c index edcc5bb0a..fe58ab832 100644 --- a/builtin.c +++ b/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, diff --git a/path.c b/path.c index 7cb3e0a5a..f30ceee7a 100644 --- a/path.c +++ b/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; }