ShellPkg: fix mv and cp command related issues

1.mv deletes file/directory when trying to move it to non-existing file system.
2.mv causes RSOD in system when trying to move same file at the same location.
3.Refactor mv and cp command with command name passed-in.
remove redundant move status error message when file failed to move across file system.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Tapan Shah <tapandshah@hp.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17129 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Tapan Shah 2015-04-07 20:39:22 +00:00 committed by jcarsey
parent bbf57d4fb9
commit bf6bbc212d
3 changed files with 31 additions and 14 deletions

View File

@ -53,6 +53,7 @@ ValidateAndCopyFiles(
@param[in] Dest pointer to destination file name
@param[out] Resp pointer to response from question. Pass back on looped calling
@param[in] SilentMode whether to run in quiet mode or not
@param[in] CmdName Source command name requesting single file copy
@retval SHELL_SUCCESS The source file was copied to the destination
**/
@ -62,7 +63,8 @@ CopySingleFile(
IN CONST CHAR16 *Source,
IN CONST CHAR16 *Dest,
OUT VOID **Resp,
IN BOOLEAN SilentMode
IN BOOLEAN SilentMode,
IN CONST CHAR16 *CmdName
)
{
VOID *Response;
@ -132,7 +134,7 @@ CopySingleFile(
if (ShellIsDirectory(Source) == EFI_SUCCESS) {
Status = ShellCreateDirectory(Dest, &DestHandle);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_DIR_FAIL), gShellLevel2HiiHandle, L"cp", Dest);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_DIR_FAIL), gShellLevel2HiiHandle, CmdName, Dest);
return (SHELL_ACCESS_DENIED);
}
@ -161,7 +163,7 @@ CopySingleFile(
//
Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_OPEN_FAIL), gShellLevel2HiiHandle, L"cp", Dest);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_OPEN_FAIL), gShellLevel2HiiHandle, CmdName, Dest);
return (SHELL_ACCESS_DENIED);
}
@ -217,7 +219,7 @@ CopySingleFile(
//not enough space on destination directory to copy file
//
SHELL_FREE_NON_NULL(DestVolumeInfo);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle, L"cp");
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle, CmdName);
return(SHELL_VOLUME_FULL);
} else {
//
@ -231,12 +233,12 @@ CopySingleFile(
Status = ShellWriteFile(DestHandle, &ReadSize, Buffer);
if (EFI_ERROR(Status)) {
ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_WRITE_ERROR), gShellLevel2HiiHandle, L"cp", Dest);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_WRITE_ERROR), gShellLevel2HiiHandle, CmdName, Dest);
break;
}
} else {
ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_READ_ERROR), gShellLevel2HiiHandle, L"cp", Source);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_READ_ERROR), gShellLevel2HiiHandle, CmdName, Source);
break;
}
}
@ -531,7 +533,7 @@ ValidateAndCopyFiles(
//
// copy single file...
//
ShellStatus = CopySingleFile(Node->FullName, DestPath, &Response, SilentMode);
ShellStatus = CopySingleFile(Node->FullName, DestPath, &Response, SilentMode, L"cp");
if (ShellStatus != SHELL_SUCCESS) {
break;
}

View File

@ -128,7 +128,7 @@ IsValidMove(
//
// If they're the same, or if source is "above" dest on file path tree
//
if ( StrCmp(DestPathWalker, SourcePath) == 0
if ( StringNoCaseCompare (&DestPathWalker, &SourcePath) == 0
|| StrStr(DestPathWalker, SourcePath) == DestPathWalker
) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_SUB), gShellLevel2HiiHandle);
@ -291,25 +291,33 @@ MoveBetweenFileSystems(
OUT VOID **Resp
)
{
EFI_STATUS Status;
SHELL_STATUS ShellStatus;
//
// First we copy the file
//
Status = CopySingleFile(Node->FullName, DestPath, Resp, TRUE);
ShellStatus = CopySingleFile (Node->FullName, DestPath, Resp, TRUE, L"mv");
//
// Check our result
//
if (!EFI_ERROR(Status)) {
if (ShellStatus == SHELL_SUCCESS) {
//
// The copy was successful. delete the source file.
//
CascadeDelete(Node, TRUE);
Node->Handle = NULL;
} else if (ShellStatus == SHELL_ABORTED) {
return EFI_ABORTED;
} else if (ShellStatus == SHELL_ACCESS_DENIED) {
return EFI_ACCESS_DENIED;
} else if (ShellStatus == SHELL_VOLUME_FULL) {
return EFI_VOLUME_FULL;
} else {
return EFI_UNSUPPORTED;
}
return (Status);
return (EFI_SUCCESS);
}
/**
@ -587,13 +595,18 @@ ValidateAndMoveFiles(
Status = MoveBetweenFileSystems(Node, FullDestPath!=NULL? FullDestPath:DestPath, &Response);
} else {
Status = MoveWithinFileSystems(Node, DestPath, &Response);
//
// Display error status
//
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, L"mv", Status);
}
}
//
// Check our result
//
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
ShellStatus = SHELL_INVALID_PARAMETER;
if (Status == EFI_SECURITY_VIOLATION) {
ShellStatus = SHELL_SECURITY_VIOLATION;

View File

@ -338,6 +338,7 @@ ShellCommandRunVol (
@param[in] Dest pointer to destination file name
@param[out] Resp pointer to response from question. Pass back on looped calling
@param[in] SilentMode whether to run in quiet mode or not
@param[in] CmdName Source command name requesting single file copy
@retval SHELL_SUCCESS The source file was copied to the destination
**/
@ -347,7 +348,8 @@ CopySingleFile(
IN CONST CHAR16 *Source,
IN CONST CHAR16 *Dest,
OUT VOID **Resp,
IN BOOLEAN SilentMode
IN BOOLEAN SilentMode,
IN CONST CHAR16 *CmdName
);
/**