]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: fix mv and cp command related issues
authorTapan Shah <tapandshah@hp.com>
Tue, 7 Apr 2015 20:39:22 +0000 (20:39 +0000)
committerjcarsey <jcarsey@Edk2>
Tue, 7 Apr 2015 20:39:22 +0000 (20:39 +0000)
1.mv deletes file/directory when trying to move it to non-existing file system.
2.mv causes RSOD in system when trying to move same file at the same location.
3.Refactor mv and cp command with command name passed-in.
remove redundant move status error message when file failed to move across file system.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Tapan Shah <tapandshah@hp.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17129 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h

index f857767047986a9d60ecd855d0f513c68b905e39..ffe1ebce6a06b4595554091054513720cc289357 100644 (file)
@@ -53,6 +53,7 @@ ValidateAndCopyFiles(
   @param[in] Dest       pointer to destination file name\r
   @param[out] Resp      pointer to response from question.  Pass back on looped calling\r
   @param[in] SilentMode whether to run in quiet mode or not\r
+  @param[in] CmdName    Source command name requesting single file copy\r
 \r
   @retval SHELL_SUCCESS   The source file was copied to the destination\r
 **/\r
@@ -62,7 +63,8 @@ CopySingleFile(
   IN CONST CHAR16 *Source,\r
   IN CONST CHAR16 *Dest,\r
   OUT VOID        **Resp,\r
-  IN BOOLEAN      SilentMode\r
+  IN BOOLEAN      SilentMode,\r
+  IN CONST CHAR16 *CmdName\r
   )\r
 {\r
   VOID                  *Response;\r
@@ -132,7 +134,7 @@ CopySingleFile(
   if (ShellIsDirectory(Source) == EFI_SUCCESS) {\r
     Status = ShellCreateDirectory(Dest, &DestHandle);\r
     if (EFI_ERROR(Status)) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_DIR_FAIL), gShellLevel2HiiHandle, L"cp", Dest);  \r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_DIR_FAIL), gShellLevel2HiiHandle, CmdName, Dest);  \r
       return (SHELL_ACCESS_DENIED);\r
     }\r
 \r
@@ -161,7 +163,7 @@ CopySingleFile(
     //\r
     Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);\r
     if (EFI_ERROR(Status)) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_OPEN_FAIL), gShellLevel2HiiHandle, L"cp", Dest);  \r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_OPEN_FAIL), gShellLevel2HiiHandle, CmdName, Dest);  \r
       return (SHELL_ACCESS_DENIED);\r
     }\r
 \r
@@ -217,7 +219,7 @@ CopySingleFile(
       //not enough space on destination directory to copy file\r
       //\r
       SHELL_FREE_NON_NULL(DestVolumeInfo);\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle, L"cp");  \r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle, CmdName);  \r
       return(SHELL_VOLUME_FULL);\r
     } else {\r
       //\r
@@ -231,12 +233,12 @@ CopySingleFile(
           Status = ShellWriteFile(DestHandle, &ReadSize, Buffer);\r
           if (EFI_ERROR(Status)) {\r
             ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_WRITE_ERROR), gShellLevel2HiiHandle, L"cp", Dest);   \r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_WRITE_ERROR), gShellLevel2HiiHandle, CmdName, Dest);   \r
             break;\r
           }\r
         } else {\r
           ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_READ_ERROR), gShellLevel2HiiHandle, L"cp", Source);  \r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_READ_ERROR), gShellLevel2HiiHandle, CmdName, Source);  \r
           break;\r
         }\r
       }\r
@@ -531,7 +533,7 @@ ValidateAndCopyFiles(
     //\r
     // copy single file...\r
     //\r
-    ShellStatus = CopySingleFile(Node->FullName, DestPath, &Response, SilentMode);\r
+    ShellStatus = CopySingleFile(Node->FullName, DestPath, &Response, SilentMode, L"cp");\r
     if (ShellStatus != SHELL_SUCCESS) {\r
       break;\r
     }\r
index 916020419509469f6c4f74defe8dc15bc3de7215..c025cebe5689a6303c6fa3f37e99ef3ac43e2534 100644 (file)
@@ -128,7 +128,7 @@ IsValidMove(
   //\r
   // If they're the same, or if source is "above" dest on file path tree\r
   //\r
-  if ( StrCmp(DestPathWalker, SourcePath) == 0 \r
+  if ( StringNoCaseCompare (&DestPathWalker, &SourcePath) == 0 \r
     || StrStr(DestPathWalker, SourcePath) == DestPathWalker \r
     ) {\r
     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_SUB), gShellLevel2HiiHandle);\r
@@ -291,25 +291,33 @@ MoveBetweenFileSystems(
   OUT VOID                **Resp\r
   )\r
 {\r
-  EFI_STATUS    Status;\r
+  SHELL_STATUS    ShellStatus;\r
 \r
   //\r
   // First we copy the file\r
   //\r
-  Status = CopySingleFile(Node->FullName, DestPath, Resp, TRUE);\r
+  ShellStatus = CopySingleFile (Node->FullName, DestPath, Resp, TRUE, L"mv");\r
 \r
   //\r
   // Check our result\r
   //\r
-  if (!EFI_ERROR(Status)) {\r
+  if (ShellStatus == SHELL_SUCCESS) {\r
     //\r
     // The copy was successful.  delete the source file.\r
     //\r
     CascadeDelete(Node, TRUE);\r
     Node->Handle = NULL;\r
+  } else if (ShellStatus == SHELL_ABORTED) {\r
+    return EFI_ABORTED;\r
+  } else if (ShellStatus == SHELL_ACCESS_DENIED) {\r
+    return EFI_ACCESS_DENIED;\r
+  } else if (ShellStatus == SHELL_VOLUME_FULL) {\r
+    return EFI_VOLUME_FULL;\r
+  } else {\r
+    return EFI_UNSUPPORTED;\r
   }\r
 \r
-  return (Status);\r
+  return (EFI_SUCCESS);\r
 }\r
 \r
 /**\r
@@ -587,13 +595,18 @@ ValidateAndMoveFiles(
       Status = MoveBetweenFileSystems(Node, FullDestPath!=NULL? FullDestPath:DestPath, &Response);\r
     } else {\r
       Status = MoveWithinFileSystems(Node, DestPath, &Response);\r
+      //\r
+      // Display error status\r
+      //\r
+      if (EFI_ERROR(Status)) {\r
+        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, L"mv", Status);\r
+      }\r
     }\r
 \r
     //\r
     // Check our result\r
     //\r
     if (EFI_ERROR(Status)) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);\r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
       if (Status == EFI_SECURITY_VIOLATION) {\r
         ShellStatus = SHELL_SECURITY_VIOLATION;\r
index 05582da3ca8dcb76694428d315f2fb0d84ed3575..634515e4933ba63a062b3f1a0f0ce060cbf7b54a 100644 (file)
@@ -338,6 +338,7 @@ ShellCommandRunVol (
   @param[in] Dest       pointer to destination file name\r
   @param[out] Resp      pointer to response from question.  Pass back on looped calling\r
   @param[in] SilentMode whether to run in quiet mode or not\r
+  @param[in] CmdName    Source command name requesting single file copy\r
 \r
   @retval SHELL_SUCCESS   The source file was copied to the destination\r
 **/\r
@@ -347,7 +348,8 @@ CopySingleFile(
   IN CONST CHAR16 *Source,\r
   IN CONST CHAR16 *Dest,\r
   OUT VOID        **Resp,\r
-  IN BOOLEAN      SilentMode\r
+  IN BOOLEAN      SilentMode,\r
+  IN CONST CHAR16 *CmdName\r
   );\r
 \r
 /**\r