ShellPkg: refine the logic for cp command

Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <Erik.c.Bjorge@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14394 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Eric Dong 2013-06-04 01:06:22 +00:00 committed by ydong10
parent 7ff3b9494d
commit ed053afece
1 changed files with 23 additions and 13 deletions

View File

@ -314,11 +314,6 @@ ValidateAndCopyFiles(
ASSERT(FileList != NULL);
ASSERT(DestDir != NULL);
//
// We already verified that this was present.
//
ASSERT(Cwd != NULL);
//
// If we are trying to copy multiple files... make sure we got a directory for the target...
//
@ -342,7 +337,7 @@ ValidateAndCopyFiles(
NewSize = StrSize(DestDir);
NewSize += StrSize(Node->FullName);
NewSize += StrSize(Cwd);
NewSize += (Cwd == NULL)? 0 : StrSize(Cwd);
if (NewSize > PathLen) {
PathLen = NewSize;
}
@ -405,7 +400,12 @@ ValidateAndCopyFiles(
//
// simple copy of a single file
//
StrCpy(DestPath, Cwd);
if (Cwd != NULL) {
StrCpy(DestPath, Cwd);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);
return (SHELL_INVALID_PARAMETER);
}
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
StrCat(DestPath, L"\\");
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
@ -424,15 +424,25 @@ ValidateAndCopyFiles(
// Check for leading slash
//
if (DestDir[0] == L'\\') {
//
// Copy to the root of CWD
//
StrCpy(DestPath, Cwd);
//
// Copy to the root of CWD
//
if (Cwd != NULL) {
StrCpy(DestPath, Cwd);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);
return (SHELL_INVALID_PARAMETER);
}
while (PathRemoveLastItem(DestPath));
StrCat(DestPath, DestDir+1);
StrCat(DestPath, Node->FileName);
} else if (StrStr(DestDir, L":") == NULL) {
StrCpy(DestPath, Cwd);
if (Cwd != NULL) {
StrCpy(DestPath, Cwd);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);
return (SHELL_INVALID_PARAMETER);
}
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
StrCat(DestPath, L"\\");
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
@ -562,7 +572,7 @@ ProcessValidateAndCopyFiles(
SHELL_FREE_NON_NULL(FileInfo);
ShellCloseFileMetaArg(&List);
} else {
ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
}
return (ShellStatus);