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:
@@ -314,11 +314,6 @@ ValidateAndCopyFiles(
|
|||||||
ASSERT(FileList != NULL);
|
ASSERT(FileList != NULL);
|
||||||
ASSERT(DestDir != 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...
|
// 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(DestDir);
|
||||||
NewSize += StrSize(Node->FullName);
|
NewSize += StrSize(Node->FullName);
|
||||||
NewSize += StrSize(Cwd);
|
NewSize += (Cwd == NULL)? 0 : StrSize(Cwd);
|
||||||
if (NewSize > PathLen) {
|
if (NewSize > PathLen) {
|
||||||
PathLen = NewSize;
|
PathLen = NewSize;
|
||||||
}
|
}
|
||||||
@@ -405,7 +400,12 @@ ValidateAndCopyFiles(
|
|||||||
//
|
//
|
||||||
// simple copy of a single file
|
// 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'\\') {
|
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
|
||||||
StrCat(DestPath, L"\\");
|
StrCat(DestPath, L"\\");
|
||||||
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
|
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
|
||||||
@@ -424,15 +424,25 @@ ValidateAndCopyFiles(
|
|||||||
// Check for leading slash
|
// Check for leading slash
|
||||||
//
|
//
|
||||||
if (DestDir[0] == L'\\') {
|
if (DestDir[0] == L'\\') {
|
||||||
//
|
//
|
||||||
// Copy to the root of CWD
|
// Copy to the root of CWD
|
||||||
//
|
//
|
||||||
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);
|
||||||
|
}
|
||||||
while (PathRemoveLastItem(DestPath));
|
while (PathRemoveLastItem(DestPath));
|
||||||
StrCat(DestPath, DestDir+1);
|
StrCat(DestPath, DestDir+1);
|
||||||
StrCat(DestPath, Node->FileName);
|
StrCat(DestPath, Node->FileName);
|
||||||
} else if (StrStr(DestDir, L":") == NULL) {
|
} 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'\\') {
|
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
|
||||||
StrCat(DestPath, L"\\");
|
StrCat(DestPath, L"\\");
|
||||||
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
|
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
|
||||||
@@ -562,7 +572,7 @@ ProcessValidateAndCopyFiles(
|
|||||||
SHELL_FREE_NON_NULL(FileInfo);
|
SHELL_FREE_NON_NULL(FileInfo);
|
||||||
ShellCloseFileMetaArg(&List);
|
ShellCloseFileMetaArg(&List);
|
||||||
} else {
|
} else {
|
||||||
ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
|
ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (ShellStatus);
|
return (ShellStatus);
|
||||||
|
Reference in New Issue
Block a user