Main file for mv shell level 2 function.\r
\r
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
- Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
@retval FALSE The move is within a file system.\r
**/\r
BOOLEAN\r
-EFIAPI\r
IsBetweenFileSystem(\r
IN CONST CHAR16 *FullName,\r
IN CONST CHAR16 *Cwd,\r
return (FALSE);\r
}\r
\r
+/**\r
+ function to determine if SrcPath is valid to mv.\r
+\r
+ if SrcPath equal CWD then it's invalid.\r
+ if SrcPath is the parent path of CWD then it's invalid.\r
+ is SrcPath is NULL return FALSE.\r
+\r
+ if CwdPath is NULL then ASSERT()\r
+\r
+ @param SrcPath [in] The source path.\r
+ @param CwdPath [in] The current working directory.\r
+\r
+ @retval TRUE The source path is valid.\r
+ @retval FALSE The source path is invalid.\r
+**/\r
+BOOLEAN\r
+IsSoucePathValid(\r
+ IN CONST CHAR16* SrcPath,\r
+ IN CONST CHAR16* CwdPath\r
+ )\r
+{\r
+ CHAR16* SrcPathBuffer;\r
+ CHAR16* CwdPathBuffer;\r
+ BOOLEAN Ret;\r
+\r
+ ASSERT (CwdPath != NULL);\r
+ if (SrcPath == NULL) {\r
+ return FALSE;\r
+ }\r
+\r
+ Ret = TRUE;\r
+\r
+ SrcPathBuffer = AllocateCopyPool (StrSize (SrcPath), SrcPath);\r
+ if (SrcPathBuffer == NULL) {\r
+ return FALSE;\r
+ }\r
+\r
+ CwdPathBuffer = AllocateCopyPool (StrSize (CwdPath), CwdPath);\r
+ if (CwdPathBuffer == NULL) {\r
+ FreePool(SrcPathBuffer);\r
+ return FALSE;\r
+ }\r
+\r
+ gUnicodeCollation->StrUpr (gUnicodeCollation, SrcPathBuffer);\r
+ gUnicodeCollation->StrUpr (gUnicodeCollation, CwdPathBuffer);\r
+\r
+ if (SrcPathBuffer[StrLen (SrcPathBuffer) -1 ] == L'\\') {\r
+ SrcPathBuffer[StrLen (SrcPathBuffer) - 1] = CHAR_NULL;\r
+ }\r
+\r
+ if (CwdPathBuffer[StrLen (CwdPathBuffer) - 1] == L'\\') {\r
+ CwdPathBuffer[StrLen (CwdPathBuffer) - 1] = CHAR_NULL;\r
+ }\r
+\r
+ if (StrCmp (CwdPathBuffer, SrcPathBuffer) == 0 ||\r
+ ((StrStr (CwdPathBuffer, SrcPathBuffer) == CwdPathBuffer) &&\r
+ (CwdPathBuffer[StrLen (SrcPathBuffer)] == L'\\'))\r
+ ) {\r
+ Ret = FALSE;\r
+ }\r
+\r
+ FreePool (SrcPathBuffer);\r
+ FreePool (CwdPathBuffer);\r
+\r
+ return Ret;\r
+}\r
+\r
/**\r
Function to validate that moving a specific file (FileName) to a specific\r
location (DestPath) is valid.\r
@retval FALSE The move is not\r
**/\r
BOOLEAN\r
-EFIAPI\r
IsValidMove(\r
IN CONST CHAR16 *SourcePath,\r
IN CONST CHAR16 *Cwd,\r
CHAR16 *DestPathCopy;\r
CHAR16 *DestPathWalker;\r
\r
- if (Cwd != NULL && StrCmp(SourcePath, Cwd) == 0) {\r
- //\r
- // Invalid move\r
- //\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_CWD), gShellLevel2HiiHandle);\r
- return (FALSE);\r
+ if ((Cwd != NULL) && ((Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY)) {\r
+ if (!IsSoucePathValid (SourcePath, Cwd)) {\r
+ //\r
+ // Invalid move\r
+ //\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_MV_INV_CWD), gShellLevel2HiiHandle);\r
+ return FALSE;\r
+ }\r
}\r
\r
//\r
@retval SHELL_SUCCESS The operation was sucessful.\r
**/\r
SHELL_STATUS\r
-EFIAPI\r
GetDestinationLocation(\r
IN CONST CHAR16 *DestParameter,\r
IN OUT CHAR16 **DestPathPointer,\r
@retval SHELL_SUCCESS The source file was moved to the destination.\r
**/\r
EFI_STATUS\r
-EFIAPI\r
MoveBetweenFileSystems(\r
IN EFI_SHELL_FILE_INFO *Node,\r
IN CONST CHAR16 *DestPath,\r
@retval SHELL_OUT_OF_RESOURCES a memory allocation failed\r
**/\r
EFI_STATUS\r
-EFIAPI\r
CreateFullDestPath(\r
IN CONST CHAR16 **DestPath,\r
OUT CHAR16 **FullDestPath, \r
@retval SHELL_OUT_OF_RESOURCES A memory allocation failed.\r
**/\r
EFI_STATUS\r
-EFIAPI\r
MoveWithinFileSystems(\r
IN EFI_SHELL_FILE_INFO *Node,\r
IN CHAR16 *DestPath,\r
@retval SHELL_OUT_OF_RESOURCES a memory allocation failed\r
**/\r
SHELL_STATUS\r
-EFIAPI\r
ValidateAndMoveFiles(\r
IN EFI_SHELL_FILE_INFO *FileList,\r
OUT VOID **Resp,\r
Response = *Resp;\r
Attr = 0;\r
CleanFilePathStr = NULL;\r
+ FullCwd = NULL;\r
\r
- FullCwd = AllocateZeroPool(StrSize(Cwd) + sizeof(CHAR16));\r
- if (FullCwd == NULL) {\r
- return SHELL_OUT_OF_RESOURCES;\r
- } else {\r
- StrCpyS(FullCwd, StrSize(Cwd)/sizeof(CHAR16)+1, Cwd);\r
- StrCatS(FullCwd, StrSize(Cwd)/sizeof(CHAR16)+1, L"\\");\r
- }\r
+ if (Cwd != NULL) {\r
+ FullCwd = AllocateZeroPool(StrSize(Cwd) + sizeof(CHAR16));\r
+ if (FullCwd == NULL) {\r
+ return SHELL_OUT_OF_RESOURCES;\r
+ } else {\r
+ StrCpyS(FullCwd, StrSize(Cwd)/sizeof(CHAR16)+1, Cwd);\r
+ StrCatS(FullCwd, StrSize(Cwd)/sizeof(CHAR16)+1, L"\\");\r
+ }\r
+ } \r
\r
Status = ShellLevel2StripQuotes (DestParameter, &CleanFilePathStr);\r
if (EFI_ERROR (Status)) {\r
- FreePool (FullCwd);\r
+ SHELL_FREE_NON_NULL(FullCwd);\r
if (Status == EFI_OUT_OF_RESOURCES) {\r
return SHELL_OUT_OF_RESOURCES;\r
} else {\r
FreePool (CleanFilePathStr);\r
\r
if (ShellStatus != SHELL_SUCCESS) {\r
- FreePool (FullCwd);\r
+ SHELL_FREE_NON_NULL (FullCwd);\r
return (ShellStatus);\r
}\r
DestPath = PathCleanUpDirectories(DestPath);\r
SHELL_FREE_NON_NULL(DestPath);\r
SHELL_FREE_NON_NULL(HiiOutput);\r
SHELL_FREE_NON_NULL(HiiResultOk);\r
- FreePool (FullCwd);\r
+ SHELL_FREE_NON_NULL(FullCwd);\r
return (SHELL_OUT_OF_RESOURCES);\r
}\r
\r
//\r
// indicate to stop everything\r
//\r
- FreePool(FullCwd);\r
+ SHELL_FREE_NON_NULL(FullCwd);\r
return (SHELL_ABORTED);\r
case ShellPromptResponseAll:\r
*Resp = Response;\r
break;\r
default:\r
FreePool(Response);\r
- FreePool(FullCwd);\r
+ SHELL_FREE_NON_NULL(FullCwd);\r
return SHELL_ABORTED;\r
}\r
Status = ShellDeleteFileByName(FullDestPath!=NULL? FullDestPath:DestPath);\r
SHELL_FREE_NON_NULL(DestPath);\r
SHELL_FREE_NON_NULL(HiiOutput);\r
SHELL_FREE_NON_NULL(HiiResultOk);\r
- FreePool (FullCwd);\r
+ SHELL_FREE_NON_NULL(FullCwd);\r
return (ShellStatus);\r
}\r
\r
//\r
// ValidateAndMoveFiles will report errors to the screen itself\r
//\r
- CwdSize = StrSize(ShellGetCurrentDir(NULL)) + 1;\r
+ CwdSize = StrSize(ShellGetCurrentDir(NULL)) + sizeof(CHAR16);\r
Cwd = AllocateZeroPool(CwdSize);\r
- ASSERT (Cwd != NULL);\r
- StrCpyS(Cwd, CwdSize/sizeof(CHAR16), ShellGetCurrentDir(NULL));\r
- StrCatS(Cwd, CwdSize/sizeof(CHAR16), L"\\");\r
- ShellStatus = ValidateAndMoveFiles(FileList, &Response, Cwd);\r
- FreePool(Cwd);\r
+ if (Cwd == NULL) {\r
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"mv");\r
+ ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+ } else {\r
+ StrCpyS (Cwd, CwdSize / sizeof (CHAR16), ShellGetCurrentDir (NULL));\r
+ StrCatS (Cwd, CwdSize / sizeof (CHAR16), L"\\");\r
+ ShellStatus = ValidateAndMoveFiles (FileList, &Response, Cwd);\r
+ FreePool (Cwd);\r
+ }\r
}\r
}\r
\r