Module: wine Branch: master Commit: 692f4384e409ab3e43b752e4ea7bc1183dd428c0 URL: https://gitlab.winehq.org/wine/wine/-/commit/692f4384e409ab3e43b752e4ea7bc11...
Author: Eric Pouech epouech@codeweavers.com Date: Thu Jun 27 18:16:49 2024 +0200
cmd: Set success/failure return code for COPY command.
Signed-off-by: Eric Pouech epouech@codeweavers.com
---
programs/cmd/builtins.c | 45 ++++++++++++++++++-------------- programs/cmd/tests/test_builtins.cmd.exp | 8 +++--- programs/cmd/wcmd.h | 2 +- programs/cmd/wcmdmain.c | 2 +- 4 files changed, 32 insertions(+), 25 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 77f40a87fd0..faff537be73 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -606,8 +606,8 @@ static BOOL WCMD_ManualCopy(WCHAR *srcname, WCHAR *dstname, BOOL ascii, BOOL app * */
-void WCMD_copy(WCHAR * args) { - +RETURN_CODE WCMD_copy(WCHAR * args) +{ BOOL opt_d, opt_v, opt_n, opt_z, opt_y, opt_noty; WCHAR *thisparam; int argno = 0; @@ -639,15 +639,15 @@ void WCMD_copy(WCHAR * args) { COPY_FILES *destination = NULL; COPY_FILES *thiscopy = NULL; COPY_FILES *prevcopy = NULL; + RETURN_CODE return_code;
/* Assume we were successful! */ - errorlevel = NO_ERROR; + return_code = NO_ERROR;
/* If no args supplied at all, report an error */ if (param1[0] == 0x00) { WCMD_output_stderr (WCMD_LoadMessage(WCMD_NOARG)); - errorlevel = ERROR_INVALID_FUNCTION; - return; + return errorlevel = ERROR_INVALID_FUNCTION; }
opt_d = opt_v = opt_n = opt_z = opt_y = opt_noty = FALSE; @@ -726,7 +726,7 @@ void WCMD_copy(WCHAR * args) { if (*thisparam=='+') { if (lastcopyentry == NULL) { WCMD_output_stderr(WCMD_LoadMessage(WCMD_SYNTAXERR)); - errorlevel = ERROR_INVALID_FUNCTION; + return_code = ERROR_INVALID_FUNCTION; goto exitreturn; } else { concatnextfilename = TRUE; @@ -781,7 +781,7 @@ void WCMD_copy(WCHAR * args) { } else { /* We have processed sources and destinations and still found more to do - invalid */ WCMD_output_stderr(WCMD_LoadMessage(WCMD_SYNTAXERR)); - errorlevel = ERROR_INVALID_FUNCTION; + return_code = ERROR_INVALID_FUNCTION; goto exitreturn; } concatnextfilename = FALSE; @@ -798,7 +798,7 @@ void WCMD_copy(WCHAR * args) { /* Ensure we have at least one source file */ if (!sourcelist) { WCMD_output_stderr(WCMD_LoadMessage(WCMD_SYNTAXERR)); - errorlevel = ERROR_INVALID_FUNCTION; + return_code = ERROR_INVALID_FUNCTION; goto exitreturn; }
@@ -828,6 +828,7 @@ void WCMD_copy(WCHAR * args) { if (destination == NULL) {
WINE_TRACE("No destination supplied, so need to calculate it\n"); + lstrcpyW(destname, L"."); lstrcatW(destname, L"\");
@@ -846,7 +847,8 @@ void WCMD_copy(WCHAR * args) { WINE_TRACE("Destination supplied, processing to see if file or directory\n");
/* Convert to fully qualified path/filename */ - if (!WCMD_get_fullpath(destination->name, ARRAY_SIZE(destname), destname, &filenamepart)) return; + if (!WCMD_get_fullpath(destination->name, ARRAY_SIZE(destname), destname, &filenamepart)) + return errorlevel = ERROR_INVALID_FUNCTION; WINE_TRACE("Full dest name is '%s'\n", wine_dbgstr_w(destname));
/* If parameter is a directory, ensure it ends in \ */ @@ -914,6 +916,7 @@ void WCMD_copy(WCHAR * args) { thiscopy = sourcelist; prevcopy = NULL;
+ return_code = NO_ERROR; while (thiscopy != NULL) {
WCHAR srcpath[MAX_PATH]; @@ -928,7 +931,8 @@ void WCMD_copy(WCHAR * args) {
/* Convert to fully qualified path/filename in srcpath, file filenamepart pointing to where the filename portion begins (used for wildcard expansion). */ - if (!WCMD_get_fullpath(thiscopy->name, ARRAY_SIZE(srcpath), srcpath, &filenamepart)) return; + if (!WCMD_get_fullpath(thiscopy->name, ARRAY_SIZE(srcpath), srcpath, &filenamepart)) + return errorlevel = ERROR_INVALID_FUNCTION; WINE_TRACE("Full src name is '%s'\n", wine_dbgstr_w(srcpath));
/* If parameter is a directory, ensure it ends in * */ @@ -938,7 +942,8 @@ void WCMD_copy(WCHAR * args) { /* We need to know where the filename part starts, so append * and recalculate the full resulting path */ lstrcatW(thiscopy->name, L"*"); - if (!WCMD_get_fullpath(thiscopy->name, ARRAY_SIZE(srcpath), srcpath, &filenamepart)) return; + if (!WCMD_get_fullpath(thiscopy->name, ARRAY_SIZE(srcpath), srcpath, &filenamepart)) + return errorlevel = ERROR_INVALID_FUNCTION; WINE_TRACE("Directory, so full name is now '%s'\n", wine_dbgstr_w(srcpath));
} else if ((wcspbrk(srcpath, L"*?") == NULL) && @@ -948,7 +953,8 @@ void WCMD_copy(WCHAR * args) { /* We need to know where the filename part starts, so append * and recalculate the full resulting path */ lstrcatW(thiscopy->name, L"\*"); - if (!WCMD_get_fullpath(thiscopy->name, ARRAY_SIZE(srcpath), srcpath, &filenamepart)) return; + if (!WCMD_get_fullpath(thiscopy->name, ARRAY_SIZE(srcpath), srcpath, &filenamepart)) + return errorlevel = ERROR_INVALID_FUNCTION; WINE_TRACE("Directory, so full name is now '%s'\n", wine_dbgstr_w(srcpath)); }
@@ -1046,7 +1052,7 @@ void WCMD_copy(WCHAR * args) { } if (!status) { WCMD_print_error (); - errorlevel = ERROR_INVALID_FUNCTION; + return_code = ERROR_INVALID_FUNCTION; } else { WINE_TRACE("Copied successfully\n"); if (anyconcats) writtenoneconcat = TRUE; @@ -1058,11 +1064,12 @@ void WCMD_copy(WCHAR * args) { if (!destination->binarycopy && !anyconcats && !thiscopy->binarycopy) { if (!WCMD_AppendEOF(outname)) { WCMD_print_error (); - errorlevel = ERROR_INVALID_FUNCTION; + return_code = ERROR_INVALID_FUNCTION; } } } - } + } else if (prompt) + return_code = ERROR_INVALID_FUNCTION; } } while (!srcisdevice && FindNextFileW(hff, &fd) != 0); if (!srcisdevice) FindClose (hff); @@ -1070,7 +1077,7 @@ void WCMD_copy(WCHAR * args) { /* Error if the first file was not found */ if (!anyconcats || !writtenoneconcat) { WCMD_print_error (); - errorlevel = ERROR_INVALID_FUNCTION; + return_code = ERROR_INVALID_FUNCTION; } }
@@ -1079,10 +1086,10 @@ void WCMD_copy(WCHAR * args) { }
/* Append EOF if ascii destination and we were concatenating */ - if (!errorlevel && !destination->binarycopy && anyconcats && writtenoneconcat) { + if (!return_code && !destination->binarycopy && anyconcats && writtenoneconcat) { if (!WCMD_AppendEOF(destination->name)) { WCMD_print_error (); - errorlevel = ERROR_INVALID_FUNCTION; + return_code = ERROR_INVALID_FUNCTION; } }
@@ -1104,7 +1111,7 @@ exitreturn: free(destination); }
- return; + return errorlevel = return_code; }
/**************************************************************************** diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index c17f00c0c02..8b281907624 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -474,11 +474,11 @@ FAILURE 1 @todo_wine@--- FAILURE 1 --- success/failure for COPY command -@todo_wine@FAILURE 1 +FAILURE 1 SUCCESS 0 -@todo_wine@FAILURE 1 -@todo_wine@FAILURE 1 -@todo_wine@FAILURE 1 +FAILURE 1 +FAILURE 1 +FAILURE 1 --- success/failure for MOVE command FAILURE 1 SUCCESS 0 diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h index 752ee251cd2..0b0a96c5fb8 100644 --- a/programs/cmd/wcmd.h +++ b/programs/cmd/wcmd.h @@ -166,7 +166,7 @@ void WCMD_change_tty (void); void WCMD_choice (const WCHAR *); void WCMD_clear_screen (void); void WCMD_color (void); -void WCMD_copy (WCHAR *); +RETURN_CODE WCMD_copy(WCHAR *); void WCMD_create_dir (WCHAR *); RETURN_CODE WCMD_delete(WCHAR *); void WCMD_directory (WCHAR *); diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 5e429c2f3f0..c096abe3431 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -1820,7 +1820,7 @@ static RETURN_CODE execute_single_command(const WCHAR *command) WCMD_clear_screen (); break; case WCMD_COPY: - WCMD_copy (parms_start); + return_code = WCMD_copy(parms_start); break; case WCMD_CTTY: WCMD_change_tty ();