]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: fix support for "\" (or "\.") meaning root of drive.
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 20 Sep 2011 21:01:34 +0000 (21:01 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 20 Sep 2011 21:01:34 +0000 (21:01 +0000)
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

ShellPkg/Library/BasePathLib/BasePathLib.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c

index 77d5866a817af43a5b144c76759d9b230bb7ccef..2166c9d8af06a138eb147551c166c00dab91874a 100644 (file)
@@ -112,7 +112,7 @@ PathCleanUpDirectories(
     CopyMem(Path+StrLen(Path), TempString, TempSize);\r
   }\r
   if ((TempString = StrStr(Path, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) {\r
-    *TempString = CHAR_NULL;\r
+    *(TempString + 1) = CHAR_NULL;\r
   }\r
 \r
 \r
index 82d1c39df0cdffea0b5bf35db0bbf4bc7e0139e7..c753702e816be46ff7489d552ff6cb72049b22fb 100644 (file)
@@ -37,6 +37,7 @@ ShellCommandRunCd (
   SHELL_STATUS      ShellStatus;\r
   SHELL_FILE_HANDLE Handle;\r
   CONST CHAR16      *Param1;\r
+  CHAR16            *Param1Copy;\r
 \r
   ProblemParam = NULL;\r
   ShellStatus = SHELL_SUCCESS;\r
@@ -94,11 +95,13 @@ ShellCommandRunCd (
         ShellStatus = SHELL_NOT_FOUND;\r
       }\r
     } else {\r
-      if (StrCmp(Param1, L".") == 0) {\r
+      Param1Copy = CatSPrint(NULL, L"%s", Param1, NULL);\r
+      Param1Copy = PathCleanUpDirectories(Param1Copy);\r
+      if (StrCmp(Param1Copy, L".") == 0) {\r
         //\r
         // nothing to do... change to current directory\r
         //\r
-      } else if (StrCmp(Param1, L"..") == 0) {\r
+      } else if (StrCmp(Param1Copy, L"..") == 0) {\r
         //\r
         // Change up one directory...\r
         //\r
@@ -120,7 +123,7 @@ ShellCommandRunCd (
             ShellStatus = SHELL_NOT_FOUND;\r
           }\r
         }\r
-      } else if (StrCmp(Param1, L"\\") == 0) {\r
+      } else if (StrCmp(Param1Copy, L"\\") == 0) {\r
         //\r
         // Move to root of current drive\r
         //\r
@@ -142,18 +145,18 @@ ShellCommandRunCd (
             ShellStatus = SHELL_NOT_FOUND;\r
           }\r
         }\r
-      } else if (StrStr(Param1, L":") == NULL) {\r
+      } else if (StrStr(Param1Copy, L":") == NULL) {\r
         if (ShellGetCurrentDir(NULL) == NULL) {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
           ShellStatus = SHELL_NOT_FOUND;\r
         } else {\r
           ASSERT((Drive == NULL && DriveSize == 0) || (Drive != NULL));\r
           Drive = StrnCatGrow(&Drive, &DriveSize, ShellGetCurrentDir(NULL), 0);\r
-          if (*Param1 == L'\\') {\r
+          if (*Param1Copy == L'\\') {\r
             while (PathRemoveLastItem(Drive)) ;\r
-            Drive = StrnCatGrow(&Drive, &DriveSize, Param1+1, 0);\r
+            Drive = StrnCatGrow(&Drive, &DriveSize, Param1Copy+1, 0);\r
           } else {\r
-            Drive = StrnCatGrow(&Drive, &DriveSize, Param1, 0);\r
+            Drive = StrnCatGrow(&Drive, &DriveSize, Param1Copy, 0);\r
           }\r
           //\r
           // Verify that this is a valid directory\r
@@ -185,12 +188,12 @@ ShellCommandRunCd (
         //\r
         // change directory on other drive letter\r
         //\r
-        Drive = AllocateZeroPool(StrSize(Param1));\r
+        Drive = AllocateZeroPool(StrSize(Param1Copy));\r
         if (Drive == NULL) {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);\r
           ShellStatus = SHELL_OUT_OF_RESOURCES;\r
         } else {\r
-          Drive = StrCpy(Drive, Param1);\r
+          Drive = StrCpy(Drive, Param1Copy);\r
           Path = StrStr(Drive, L":");\r
           ASSERT(Path != NULL);\r
           if (*(Path+1) == CHAR_NULL) {\r
@@ -210,11 +213,12 @@ ShellCommandRunCd (
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
             Status = SHELL_NOT_FOUND;\r
           } else if (EFI_ERROR(Status)) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1);\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1Copy);\r
             Status = SHELL_NOT_FOUND;\r
           }\r
         }\r
       }\r
+      FreePool(Param1Copy);\r
     }\r
   }\r
 \r
index 08f5514cf54be387f6dc4c6af6994af172afb1fc..00b51b411197e34cf0aaa7a8097681998d684518 100644 (file)
@@ -359,7 +359,19 @@ ValidateAndCopyFiles(
       //\r
       // we have multiple files or a directory in the DestDir\r
       //\r
-      if (StrStr(DestDir, L":") == NULL) {\r
+      \r
+      //\r
+      // Check for leading slash\r
+      //\r
+      if (DestDir[0] == L'\\') {\r
+         //\r
+         // Copy to the root of CWD\r
+         //\r
+        StrCpy(DestPath, Cwd);\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 (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
           StrCat(DestPath, L"\\");\r