From 5830ccb85ee4083d7f0f0c482e5420a33993fc0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Wed, 1 Jul 2020 02:39:25 +0200 Subject: [PATCH] [CMD] Improve the way the ErrorMessage() helper and the MKDIR and RMDIR commands report their errors. For MKDIR, also properly support the case of ERROR_FILE_EXISTS and ERROR_ALREADY_EXISTS last-errors by displaying the standard error "A subdirectory or file XXX already exists.\n" --- base/shell/cmd/error.c | 2 +- base/shell/cmd/internal.c | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/base/shell/cmd/error.c b/base/shell/cmd/error.c index 193f785caca..be422f33cf4 100644 --- a/base/shell/cmd/error.c +++ b/base/shell/cmd/error.c @@ -50,7 +50,7 @@ ErrorMessage( NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&szError, 0, NULL)) { - ConErrPrintf(_T("%s %s\n"), szError, szMessage); + ConErrPrintf(_T("%s%s%s"), szError, szMessage, (*szMessage ? _T("\n") : _T(""))); if (szError) LocalFree(szError); return; diff --git a/base/shell/cmd/internal.c b/base/shell/cmd/internal.c index 8798eecdd31..95416b4278b 100644 --- a/base/shell/cmd/internal.c +++ b/base/shell/cmd/internal.c @@ -327,6 +327,8 @@ INT cmd_mkdir (LPTSTR param) { LPTSTR *p; INT argc, i; + DWORD dwLastError; + if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_MKDIR_HELP); @@ -347,13 +349,20 @@ INT cmd_mkdir (LPTSTR param) { if (!MakeFullPath(p[i])) { - if (GetLastError() == ERROR_PATH_NOT_FOUND) + dwLastError = GetLastError(); + switch (dwLastError) { + case ERROR_PATH_NOT_FOUND: ConErrResPuts(STRING_MD_ERROR2); - } - else - { - ErrorMessage (GetLastError(), _T("MD")); + break; + + case ERROR_FILE_EXISTS: + case ERROR_ALREADY_EXISTS: + ConErrResPrintf(STRING_MD_ERROR, p[i]); + break; + + default: + ErrorMessage(GetLastError(), NULL); } nErrorLevel = 1; } @@ -504,7 +513,7 @@ INT cmd_rmdir(LPTSTR param) { /* Couldn't delete the folder, print out the error */ nError = GetLastError(); - ErrorMessage(nError, _T("RD")); + ErrorMessage(nError, NULL); } }