]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: refine the logic for cp command
authorEric Dong <eric.dong@intel.com>
Tue, 4 Jun 2013 01:06:22 +0000 (01:06 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 4 Jun 2013 01:06:22 +0000 (01:06 +0000)
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

ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c

index 4443212a12009f9d4ef4d2e6d5db61f9cece5b19..80d2dd02bc733b952f2c6c03b64fbced9bd6b410 100644 (file)
@@ -314,11 +314,6 @@ ValidateAndCopyFiles(
   ASSERT(FileList != NULL);\r
   ASSERT(DestDir  != NULL);\r
 \r
-  //\r
-  // We already verified that this was present.\r
-  //\r
-  ASSERT(Cwd      != NULL);\r
-\r
   //\r
   // If we are trying to copy multiple files... make sure we got a directory for the target...\r
   //\r
@@ -342,7 +337,7 @@ ValidateAndCopyFiles(
 \r
     NewSize =  StrSize(DestDir);\r
     NewSize += StrSize(Node->FullName);\r
-    NewSize += StrSize(Cwd);\r
+    NewSize += (Cwd == NULL)? 0 : StrSize(Cwd);\r
     if (NewSize > PathLen) {\r
       PathLen = NewSize;\r
     }\r
@@ -405,7 +400,12 @@ ValidateAndCopyFiles(
         //\r
         // simple copy of a single file\r
         //\r
-        StrCpy(DestPath, Cwd);\r
+        if (Cwd != NULL) {\r
+          StrCpy(DestPath, Cwd);\r
+        } else {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
+          return (SHELL_INVALID_PARAMETER);\r
+        }\r
         if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
           StrCat(DestPath, L"\\");\r
         } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r
@@ -424,15 +424,25 @@ ValidateAndCopyFiles(
       // Check for leading slash\r
       //\r
       if (DestDir[0] == L'\\') {\r
-          //\r
-          // Copy to the root of CWD\r
-          //\r
-        StrCpy(DestPath, Cwd);\r
+         //\r
+         // Copy to the root of CWD\r
+         //\r
+        if (Cwd != NULL) {\r
+          StrCpy(DestPath, Cwd);\r
+        } else {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
+          return (SHELL_INVALID_PARAMETER);\r
+        }\r
         while (PathRemoveLastItem(DestPath));\r
         StrCat(DestPath, DestDir+1);\r
         StrCat(DestPath, Node->FileName);\r
       } else if (StrStr(DestDir, L":") == NULL) {\r
-        StrCpy(DestPath, Cwd);\r
+        if (Cwd != NULL) {\r
+          StrCpy(DestPath, Cwd);\r
+        } else {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
+          return (SHELL_INVALID_PARAMETER);\r
+        }\r
         if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
           StrCat(DestPath, L"\\");\r
         } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r
@@ -562,7 +572,7 @@ ProcessValidateAndCopyFiles(
     SHELL_FREE_NON_NULL(FileInfo);\r
     ShellCloseFileMetaArg(&List);\r
   } else {\r
-      ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);\r
+    ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);\r
   }\r
 \r
   return (ShellStatus);\r