ShellPkg: fix support for "\" (or "\.") meaning root of drive.

Cp command fixed to allow for copying single or multiple files to the root of the drive with destination directory \.
Cd command fixed to allow for changing CWD to the root of the drive with destination directory \.

signed-off-by: jcarsey
reviewed-by: geekboy15a

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12392 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jcarsey 2011-09-20 21:01:34 +00:00
parent e291948ce0
commit 1fc3749dad
3 changed files with 28 additions and 12 deletions

View File

@ -112,7 +112,7 @@ PathCleanUpDirectories(
CopyMem(Path+StrLen(Path), TempString, TempSize);
}
if ((TempString = StrStr(Path, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) {
*TempString = CHAR_NULL;
*(TempString + 1) = CHAR_NULL;
}

View File

@ -37,6 +37,7 @@ ShellCommandRunCd (
SHELL_STATUS ShellStatus;
SHELL_FILE_HANDLE Handle;
CONST CHAR16 *Param1;
CHAR16 *Param1Copy;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
@ -94,11 +95,13 @@ ShellCommandRunCd (
ShellStatus = SHELL_NOT_FOUND;
}
} else {
if (StrCmp(Param1, L".") == 0) {
Param1Copy = CatSPrint(NULL, L"%s", Param1, NULL);
Param1Copy = PathCleanUpDirectories(Param1Copy);
if (StrCmp(Param1Copy, L".") == 0) {
//
// nothing to do... change to current directory
//
} else if (StrCmp(Param1, L"..") == 0) {
} else if (StrCmp(Param1Copy, L"..") == 0) {
//
// Change up one directory...
//
@ -120,7 +123,7 @@ ShellCommandRunCd (
ShellStatus = SHELL_NOT_FOUND;
}
}
} else if (StrCmp(Param1, L"\\") == 0) {
} else if (StrCmp(Param1Copy, L"\\") == 0) {
//
// Move to root of current drive
//
@ -142,18 +145,18 @@ ShellCommandRunCd (
ShellStatus = SHELL_NOT_FOUND;
}
}
} else if (StrStr(Param1, L":") == NULL) {
} else if (StrStr(Param1Copy, L":") == NULL) {
if (ShellGetCurrentDir(NULL) == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
ShellStatus = SHELL_NOT_FOUND;
} else {
ASSERT((Drive == NULL && DriveSize == 0) || (Drive != NULL));
Drive = StrnCatGrow(&Drive, &DriveSize, ShellGetCurrentDir(NULL), 0);
if (*Param1 == L'\\') {
if (*Param1Copy == L'\\') {
while (PathRemoveLastItem(Drive)) ;
Drive = StrnCatGrow(&Drive, &DriveSize, Param1+1, 0);
Drive = StrnCatGrow(&Drive, &DriveSize, Param1Copy+1, 0);
} else {
Drive = StrnCatGrow(&Drive, &DriveSize, Param1, 0);
Drive = StrnCatGrow(&Drive, &DriveSize, Param1Copy, 0);
}
//
// Verify that this is a valid directory
@ -185,12 +188,12 @@ ShellCommandRunCd (
//
// change directory on other drive letter
//
Drive = AllocateZeroPool(StrSize(Param1));
Drive = AllocateZeroPool(StrSize(Param1Copy));
if (Drive == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);
ShellStatus = SHELL_OUT_OF_RESOURCES;
} else {
Drive = StrCpy(Drive, Param1);
Drive = StrCpy(Drive, Param1Copy);
Path = StrStr(Drive, L":");
ASSERT(Path != NULL);
if (*(Path+1) == CHAR_NULL) {
@ -210,11 +213,12 @@ ShellCommandRunCd (
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
Status = SHELL_NOT_FOUND;
} else if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1Copy);
Status = SHELL_NOT_FOUND;
}
}
}
FreePool(Param1Copy);
}
}

View File

@ -359,7 +359,19 @@ ValidateAndCopyFiles(
//
// we have multiple files or a directory in the DestDir
//
if (StrStr(DestDir, L":") == NULL) {
//
// Check for leading slash
//
if (DestDir[0] == L'\\') {
//
// Copy to the root of CWD
//
StrCpy(DestPath, Cwd);
while (PathRemoveLastItem(DestPath));
StrCat(DestPath, DestDir+1);
StrCat(DestPath, Node->FileName);
} else if (StrStr(DestDir, L":") == NULL) {
StrCpy(DestPath, Cwd);
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
StrCat(DestPath, L"\\");