]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Fixes for the ‘ls’ command:
authorChris Phillips <chrisp@hp.com>
Fri, 18 Oct 2013 18:53:16 +0000 (18:53 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 18 Oct 2013 18:53:16 +0000 (18:53 +0000)
- Better output to print header and file not found text
- Fix file attribute argument handling
- Fix so path ending with ‘\’ or ‘*’ is handled correctly

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chris Phillips <chrisp@hp.com>
reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14786 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni

index 55267a467a02ee42cca9398c228d83d26e7d9c1d..4d0a1563e3cce37f4b5a08babb02bb4b6236385b 100644 (file)
@@ -1,6 +1,7 @@
 /** @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 - 2012, 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
@@ -72,6 +73,26 @@ PrintLsOutput(
 \r
   PathCleanUpDirectories(CorrectedPath);\r
 \r
+  if (!Sfo) {\r
+    //\r
+    // get directory name from path...\r
+    //\r
+    DirectoryName = GetFullyQualifiedPath(CorrectedPath);\r
+\r
+    //\r
+    // print header\r
+    //\r
+    ShellPrintHiiEx (\r
+      0,\r
+      gST->ConOut->Mode->CursorRow,\r
+      NULL,\r
+      STRING_TOKEN (STR_LS_HEADER_LINE1),\r
+      gShellLevel2HiiHandle,\r
+      DirectoryName\r
+     );\r
+    FreePool(DirectoryName);\r
+  }\r
+\r
   Status = ShellOpenFileMetaArg((CHAR16*)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);\r
   if (EFI_ERROR(Status)) {\r
     SHELL_FREE_NON_NULL(CorrectedPath);\r
@@ -192,25 +213,6 @@ PrintLsOutput(
     }\r
   }\r
 \r
-  if (!Sfo) {\r
-    //\r
-    // get directory name from path...\r
-    //\r
-    DirectoryName = GetFullyQualifiedPath(CorrectedPath);\r
-\r
-    //\r
-    // print header\r
-    //\r
-    ShellPrintHiiEx (\r
-      0,\r
-      gST->ConOut->Mode->CursorRow,\r
-      NULL,\r
-      STRING_TOKEN (STR_LS_HEADER_LINE1),\r
-      gShellLevel2HiiHandle,\r
-      DirectoryName\r
-     );\r
-    FreePool(DirectoryName);\r
-  }\r
   for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)\r
       ; !IsNull(&ListHead->Link, &Node->Link)\r
       ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)\r
@@ -230,21 +232,17 @@ PrintLsOutput(
        ){\r
         continue;\r
       }\r
-    } else if (Attribs != EFI_FILE_VALID_ATTR) {\r
-      if (Count == 1) {\r
-        //\r
-        // the bit must match\r
-        //\r
-        if ( (Node->Info->Attribute & Attribs) != Attribs) {\r
-          continue;\r
-        }\r
-      } else {\r
-        //\r
-        // exact match on all bits\r
-        //\r
-        if ( (Node->Info->Attribute|EFI_FILE_ARCHIVE) != (Attribs|EFI_FILE_ARCHIVE)) {\r
-          continue;\r
-        }\r
+    } else if ((Attribs != EFI_FILE_VALID_ATTR) ||\r
+               (Count == 5)) {\r
+      //\r
+      // Only matches the bits which "Attribs" contains, not\r
+      // all files/directories with any of the bits.\r
+      // Count == 5 is used to tell the difference between a user\r
+      // specifying all bits (EX: -arhsda) and just specifying\r
+      // -a (means display all files with any attribute).\r
+      //\r
+      if ( (Node->Info->Attribute & Attribs) != Attribs) {\r
+        continue;\r
       }\r
     }\r
 \r
@@ -543,7 +541,21 @@ ShellCommandRunLs (
             ASSERT((FullPath == NULL && Size == 0) || (FullPath != NULL));\r
             StrnCatGrow(&FullPath, &Size, PathName, 0);\r
             if  (ShellIsDirectory(PathName) == EFI_SUCCESS) {\r
-              StrnCatGrow(&FullPath, &Size, L"\\*", 0);\r
+              if (PathName[StrLen (PathName) - 1] == '\\') {\r
+                //\r
+                // For path ending with '\', just append '*'.\r
+                //\r
+                StrnCatGrow (&FullPath, &Size, L"*", 0);\r
+              } else if (PathName[StrLen (PathName) - 1] == '*') {\r
+                //\r
+                // For path ending with '*', do nothing.\r
+                //\r
+              } else {\r
+                //\r
+                // Otherwise, append '\*' to directory name.\r
+                //\r
+                StrnCatGrow (&FullPath, &Size, L"\\*", 0);\r
+              }\r
             }\r
           }\r
         } else {\r
@@ -568,7 +580,7 @@ ShellCommandRunLs (
             (INT16)(TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:TheTime.TimeZone)\r
            );\r
           if (ShellStatus == SHELL_NOT_FOUND) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_FILES), gShellLevel2HiiHandle);\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LS_FILE_NOT_FOUND), gShellLevel2HiiHandle);\r
           } else if (ShellStatus == SHELL_INVALID_PARAMETER) {\r
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle);\r
           } else if (ShellStatus == SHELL_ABORTED) {\r
index 08372d5ba36452e71fa8f2fe76b39a039dfd4111..f0991507c402826c6443005ed6d95312cc44e14d 100644 (file)
Binary files a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni and b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni differ