]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
ShellPkg: Follow spec to remove the last '\' char in return name of GetCurDir().
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Ls.c
index 63af5eab18884d216110df720440073607260719..25bf8ca9e13a124a40ac33bf2293b45e27536f41 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Main file for ls shell level 2 function.\r
 \r
-  Copyright (c) 2013 Hewlett-Packard Development Company, L.P.\r
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
+  Copyright (c) 2009 - 2015, 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
@@ -408,6 +408,10 @@ PrintLsOutput(
         ; !IsNull(&ListHead->Link, &Node->Link)\r
         ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)\r
         ){\r
+      if (ShellGetExecutionBreakFlag ()) {\r
+        ShellStatus = SHELL_ABORTED;\r
+        break;\r
+      }\r
       ASSERT(Node != NULL);\r
       if (LongestPath < StrSize(Node->FullName)) {\r
         LongestPath = StrSize(Node->FullName);\r
@@ -437,7 +441,7 @@ PrintLsOutput(
         }\r
       }\r
 \r
-      if (!Sfo && HeaderPrinted == FALSE) {\r
+      if (!Sfo && !HeaderPrinted) {\r
         PrintNonSfoHeader(CorrectedPath);\r
       }\r
       PrintFileInformation(Sfo, Node, &FileCount, &FileSize, &DirCount);\r
@@ -445,18 +449,21 @@ PrintLsOutput(
       HeaderPrinted = TRUE;\r
     }\r
 \r
-    if (!Sfo) {\r
+    if (!Sfo && ShellStatus != SHELL_ABORTED) {\r
       PrintNonSfoFooter(FileCount, FileSize, DirCount);\r
     }\r
   }\r
 \r
-  if (Rec) {\r
+  if (Rec && ShellStatus != SHELL_ABORTED) {\r
     //\r
     // Re-Open all the files under the starting path for directories that didnt necessarily match our file filter\r
     //\r
     ShellCloseFileMetaArg(&ListHead);\r
     CorrectedPath[0] = CHAR_NULL;\r
     CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, RootPath, 0);\r
+    if (CorrectedPath == NULL) {\r
+      return SHELL_OUT_OF_RESOURCES;\r
+    }\r
     if (CorrectedPath[StrLen(CorrectedPath)-1] != L'\\'\r
       &&CorrectedPath[StrLen(CorrectedPath)-1] != L'/') {\r
       CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, L"\\",     0);\r
@@ -490,6 +497,13 @@ PrintLsOutput(
             &FoundOne,\r
             Count,\r
             TimeZone);\r
+            \r
+          //\r
+          // Since it's running recursively, we have to break immediately when returned SHELL_ABORTED\r
+          //\r
+          if (ShellStatus == SHELL_ABORTED) {\r
+            break;\r
+          }\r
         }\r
       }\r
     }\r
@@ -498,7 +512,7 @@ PrintLsOutput(
   SHELL_FREE_NON_NULL(CorrectedPath);\r
   ShellCloseFileMetaArg(&ListHead);\r
 \r
-  if (Found == NULL && FoundOne == FALSE) {\r
+  if (Found == NULL && !FoundOne) {\r
     return (SHELL_NOT_FOUND);\r
   }\r
 \r
@@ -572,7 +586,7 @@ ShellCommandRunLs (
   Status = ShellCommandLineParse (LsParamList, &Package, &ProblemParam, TRUE);\r
   if (EFI_ERROR(Status)) {\r
     if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"ls", ProblemParam);  \r
       FreePool(ProblemParam);\r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
@@ -587,7 +601,7 @@ ShellCommandRunLs (
     }\r
 \r
     if (ShellCommandLineGetCount(Package) > 2) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"ls");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
       //\r
@@ -625,7 +639,7 @@ ShellCommandRunLs (
               Count++;\r
               continue;\r
             default:\r
-              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ATTRIBUTE), gShellLevel2HiiHandle, ShellCommandLineGetValue(Package, L"-a"));\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ATTRIBUTE), gShellLevel2HiiHandle, L"ls", ShellCommandLineGetValue(Package, L"-a"));  \r
               ShellStatus = SHELL_INVALID_PARAMETER;\r
               break;\r
           } // switch\r
@@ -646,7 +660,7 @@ ShellCommandRunLs (
           CurDir = gEfiShellProtocol->GetCurDir(NULL);\r
           if (CurDir == NULL) {\r
             ShellStatus = SHELL_NOT_FOUND;\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"ls");  \r
           }\r
           //\r
           // Copy to the 2 strings for starting path and file search string\r
@@ -655,13 +669,15 @@ ShellCommandRunLs (
           ASSERT(FullPath == NULL);\r
           StrnCatGrow(&SearchString, NULL, L"*", 0);\r
           StrnCatGrow(&FullPath, NULL, CurDir, 0);\r
+          Size = FullPath != NULL? StrSize(FullPath) : 0;\r
+          StrnCatGrow(&FullPath, &Size, L"\\", 0);\r
         } else {\r
           if (StrStr(PathName, L":") == NULL && gEfiShellProtocol->GetCurDir(NULL) == NULL) {\r
             //\r
             // If we got something and it doesnt have a fully qualified path, then we needed to have a CWD.\r
             //\r
             ShellStatus = SHELL_NOT_FOUND;\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"ls");  \r
           } else {\r
             //\r
             // We got a valid fully qualified path or we have a CWD\r
@@ -673,6 +689,8 @@ ShellCommandRunLs (
                 ShellCommandLineFreeVarList (Package);\r
                 return SHELL_OUT_OF_RESOURCES;\r
               }\r
+              Size = FullPath != NULL? StrSize(FullPath) : 0;\r
+              StrnCatGrow(&FullPath, &Size, L"\\", 0);\r
             }\r
             StrnCatGrow(&FullPath, &Size, PathName, 0);\r
             if (FullPath == NULL) {\r
@@ -698,7 +716,7 @@ ShellCommandRunLs (
         }\r
         Status = gRT->GetTime(&TheTime, NULL);\r
         if (EFI_ERROR(Status)) {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"ls", L"gRT->GetTime", Status);  \r
           TheTime.TimeZone = EFI_UNSPECIFIED_TIMEZONE;\r
         }\r
 \r
@@ -711,18 +729,18 @@ ShellCommandRunLs (
             SearchString,\r
             NULL,\r
             Count,\r
-            (INT16)(TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:TheTime.TimeZone)\r
+            TheTime.TimeZone\r
            );\r
           if (ShellStatus == SHELL_NOT_FOUND) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LS_FILE_NOT_FOUND), gShellLevel2HiiHandle);\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LS_FILE_NOT_FOUND), gShellLevel2HiiHandle, L"ls", FullPath);  \r
           } else if (ShellStatus == SHELL_INVALID_PARAMETER) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle);\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"ls", FullPath);  \r
           } else if (ShellStatus == SHELL_ABORTED) {\r
             //\r
             // Ignore aborting.\r
             //\r
           } else if (ShellStatus != SHELL_SUCCESS) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle);\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"ls", FullPath);  \r
           }\r
         }\r
       }\r