summaryrefslogtreecommitdiff
path: root/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
diff options
context:
space:
mode:
authorQiu Shumin <shumin.qiu@intel.com>2015-10-23 02:03:20 +0000
committershenshushi <shenshushi@Edk2>2015-10-23 02:03:20 +0000
commitfbd2dfadfe6fb16ab7b49fca3764e05e65d97b8a (patch)
tree62be65e0eb87049beeb36b8ac95c2f127ce13c72 /ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
parenta7e173b07a1ef336fc8d753cf85ae8473e92365a (diff)
downloadedk2-platforms-fbd2dfadfe6fb16ab7b49fca3764e05e65d97b8a.tar.xz
ShellPkg: Follow spec to remove the last '\' char in return name of GetCurDir().
In Shell spec 2.1 the return name of EFI_SHELL_PROTOCOL.GetCurDir() is defined as 'fs0:\current-dir' while in current implementation it's 'fs0:\current-dir\'. To follow spec the patch removed the redundant '\' char. Since it has been broken for a long time, some codes may depend on the broken behavior. After this change 'EFI_SHELL_PROTOCOL.GetCurDir()' and 'UefiShellLib.ShellGetCurrentDir()' will return a current directory string without tailing '\' (fs0:\current-dir), the value of Shell environment variable 'cwd' will become 'fs0:\current-dir' as well. This patch has updated all the code in EDKII to make them depend on the new behavior. Developers should check whether 'GetCurDir()' and 'ShellGetCurrentDir' are used in their source code. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Qiu Shumin <shumin.qiu@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18653 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c')
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
index fa67533743..eb7287e48a 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
@@ -467,6 +467,7 @@ ValidateAndMoveFiles(
CHAR16 *DestPath;
CHAR16 *FullDestPath;
CONST CHAR16 *Cwd;
+ CHAR16 *FullCwd;
SHELL_STATUS ShellStatus;
EFI_SHELL_FILE_INFO *Node;
VOID *Response;
@@ -483,8 +484,17 @@ ValidateAndMoveFiles(
Attr = 0;
CleanFilePathStr = NULL;
+ FullCwd = AllocateZeroPool(StrSize(Cwd) + sizeof(CHAR16));
+ if (FullCwd == NULL) {
+ return SHELL_OUT_OF_RESOURCES;
+ } else {
+ StrCpyS(FullCwd, StrSize(Cwd)/sizeof(CHAR16)+1, Cwd);
+ StrCatS(FullCwd, StrSize(Cwd)/sizeof(CHAR16)+1, L"\\");
+ }
+
Status = ShellLevel2StripQuotes (DestParameter, &CleanFilePathStr);
if (EFI_ERROR (Status)) {
+ FreePool (FullCwd);
if (Status == EFI_OUT_OF_RESOURCES) {
return SHELL_OUT_OF_RESOURCES;
} else {
@@ -497,14 +507,16 @@ ValidateAndMoveFiles(
//
// Get and validate the destination location
//
- ShellStatus = GetDestinationLocation(CleanFilePathStr, &DestPath, Cwd, (BOOLEAN)(FileList->Link.ForwardLink == FileList->Link.BackLink), &Attr);
+ ShellStatus = GetDestinationLocation(CleanFilePathStr, &DestPath, FullCwd, (BOOLEAN)(FileList->Link.ForwardLink == FileList->Link.BackLink), &Attr);
FreePool (CleanFilePathStr);
if (ShellStatus != SHELL_SUCCESS) {
+ FreePool (FullCwd);
return (ShellStatus);
}
DestPath = PathCleanUpDirectories(DestPath);
if (DestPath == NULL) {
+ FreePool (FullCwd);
return (SHELL_OUT_OF_RESOURCES);
}
@@ -514,6 +526,7 @@ ValidateAndMoveFiles(
SHELL_FREE_NON_NULL(DestPath);
SHELL_FREE_NON_NULL(HiiOutput);
SHELL_FREE_NON_NULL(HiiResultOk);
+ FreePool (FullCwd);
return (SHELL_OUT_OF_RESOURCES);
}
@@ -551,7 +564,7 @@ ValidateAndMoveFiles(
//
// Validate that the move is valid
//
- if (!IsValidMove(Node->FullName, Cwd, FullDestPath!=NULL? FullDestPath:DestPath, Node->Info->Attribute, Attr, Node->Status)) {
+ if (!IsValidMove(Node->FullName, FullCwd, FullDestPath!=NULL? FullDestPath:DestPath, Node->Info->Attribute, Attr, Node->Status)) {
ShellStatus = SHELL_INVALID_PARAMETER;
continue;
}
@@ -575,6 +588,7 @@ ValidateAndMoveFiles(
//
// indicate to stop everything
//
+ FreePool(FullCwd);
return (SHELL_ABORTED);
case ShellPromptResponseAll:
*Resp = Response;
@@ -585,12 +599,13 @@ ValidateAndMoveFiles(
break;
default:
FreePool(Response);
+ FreePool(FullCwd);
return SHELL_ABORTED;
}
Status = ShellDeleteFileByName(FullDestPath!=NULL? FullDestPath:DestPath);
}
- if (IsBetweenFileSystem(Node->FullName, Cwd, DestPath)) {
+ if (IsBetweenFileSystem(Node->FullName, FullCwd, DestPath)) {
while (FullDestPath == NULL && DestPath != NULL && DestPath[0] != CHAR_NULL && DestPath[StrLen(DestPath) - 1] == L'\\') {
DestPath[StrLen(DestPath) - 1] = CHAR_NULL;
}
@@ -631,6 +646,7 @@ ValidateAndMoveFiles(
SHELL_FREE_NON_NULL(DestPath);
SHELL_FREE_NON_NULL(HiiOutput);
SHELL_FREE_NON_NULL(HiiResultOk);
+ FreePool (FullCwd);
return (ShellStatus);
}
@@ -650,6 +666,8 @@ ShellCommandRunMv (
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
+ CHAR16 *Cwd;
+ UINTN CwdSize;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
UINTN LoopCounter;
@@ -713,7 +731,13 @@ ShellCommandRunMv (
//
// ValidateAndMoveFiles will report errors to the screen itself
//
- ShellStatus = ValidateAndMoveFiles(FileList, &Response, ShellGetCurrentDir(NULL));
+ CwdSize = StrSize(ShellGetCurrentDir(NULL)) + 1;
+ Cwd = AllocateZeroPool(CwdSize);
+ ASSERT (Cwd != NULL);
+ StrCpyS(Cwd, CwdSize/sizeof(CHAR16), ShellGetCurrentDir(NULL));
+ StrCatS(Cwd, CwdSize/sizeof(CHAR16), L"\\");
+ ShellStatus = ValidateAndMoveFiles(FileList, &Response, Cwd);
+ FreePool(Cwd);
}
}