ShellPkg: Fixes for the ‘ls’ command:
- 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
This commit is contained in:
		| @@ -1,6 +1,7 @@ | |||||||
| /** @file | /** @file | ||||||
|   Main file for ls shell level 2 function. |   Main file for ls shell level 2 function. | ||||||
|  |  | ||||||
|  |   Copyright (c) 2013 Hewlett-Packard Development Company, L.P. | ||||||
|   Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR> |   Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR> | ||||||
|   This program and the accompanying materials |   This program and the accompanying materials | ||||||
|   are licensed and made available under the terms and conditions of the BSD License |   are licensed and made available under the terms and conditions of the BSD License | ||||||
| @@ -72,6 +73,26 @@ PrintLsOutput( | |||||||
|  |  | ||||||
|   PathCleanUpDirectories(CorrectedPath); |   PathCleanUpDirectories(CorrectedPath); | ||||||
|  |  | ||||||
|  |   if (!Sfo) { | ||||||
|  |     // | ||||||
|  |     // get directory name from path... | ||||||
|  |     // | ||||||
|  |     DirectoryName = GetFullyQualifiedPath(CorrectedPath); | ||||||
|  |  | ||||||
|  |     // | ||||||
|  |     // print header | ||||||
|  |     // | ||||||
|  |     ShellPrintHiiEx ( | ||||||
|  |       0, | ||||||
|  |       gST->ConOut->Mode->CursorRow, | ||||||
|  |       NULL, | ||||||
|  |       STRING_TOKEN (STR_LS_HEADER_LINE1), | ||||||
|  |       gShellLevel2HiiHandle, | ||||||
|  |       DirectoryName | ||||||
|  |      ); | ||||||
|  |     FreePool(DirectoryName); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   Status = ShellOpenFileMetaArg((CHAR16*)CorrectedPath, EFI_FILE_MODE_READ, &ListHead); |   Status = ShellOpenFileMetaArg((CHAR16*)CorrectedPath, EFI_FILE_MODE_READ, &ListHead); | ||||||
|   if (EFI_ERROR(Status)) { |   if (EFI_ERROR(Status)) { | ||||||
|     SHELL_FREE_NON_NULL(CorrectedPath); |     SHELL_FREE_NON_NULL(CorrectedPath); | ||||||
| @@ -192,25 +213,6 @@ PrintLsOutput( | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   if (!Sfo) { |  | ||||||
|     // |  | ||||||
|     // get directory name from path... |  | ||||||
|     // |  | ||||||
|     DirectoryName = GetFullyQualifiedPath(CorrectedPath); |  | ||||||
|  |  | ||||||
|     // |  | ||||||
|     // print header |  | ||||||
|     // |  | ||||||
|     ShellPrintHiiEx ( |  | ||||||
|       0, |  | ||||||
|       gST->ConOut->Mode->CursorRow, |  | ||||||
|       NULL, |  | ||||||
|       STRING_TOKEN (STR_LS_HEADER_LINE1), |  | ||||||
|       gShellLevel2HiiHandle, |  | ||||||
|       DirectoryName |  | ||||||
|      ); |  | ||||||
|     FreePool(DirectoryName); |  | ||||||
|   } |  | ||||||
|   for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link) |   for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link) | ||||||
|       ; !IsNull(&ListHead->Link, &Node->Link) |       ; !IsNull(&ListHead->Link, &Node->Link) | ||||||
|       ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link) |       ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link) | ||||||
| @@ -230,22 +232,18 @@ PrintLsOutput( | |||||||
|        ){ |        ){ | ||||||
|         continue; |         continue; | ||||||
|       } |       } | ||||||
|     } else if (Attribs != EFI_FILE_VALID_ATTR) { |     } else if ((Attribs != EFI_FILE_VALID_ATTR) || | ||||||
|       if (Count == 1) { |                (Count == 5)) { | ||||||
|       // |       // | ||||||
|         // the bit must match |       // Only matches the bits which "Attribs" contains, not | ||||||
|  |       // all files/directories with any of the bits. | ||||||
|  |       // Count == 5 is used to tell the difference between a user | ||||||
|  |       // specifying all bits (EX: -arhsda) and just specifying | ||||||
|  |       // -a (means display all files with any attribute). | ||||||
|       // |       // | ||||||
|       if ( (Node->Info->Attribute & Attribs) != Attribs) { |       if ( (Node->Info->Attribute & Attribs) != Attribs) { | ||||||
|         continue; |         continue; | ||||||
|       } |       } | ||||||
|       } else { |  | ||||||
|         // |  | ||||||
|         // exact match on all bits |  | ||||||
|         // |  | ||||||
|         if ( (Node->Info->Attribute|EFI_FILE_ARCHIVE) != (Attribs|EFI_FILE_ARCHIVE)) { |  | ||||||
|           continue; |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (Sfo) { |     if (Sfo) { | ||||||
| @@ -543,9 +541,23 @@ ShellCommandRunLs ( | |||||||
|             ASSERT((FullPath == NULL && Size == 0) || (FullPath != NULL)); |             ASSERT((FullPath == NULL && Size == 0) || (FullPath != NULL)); | ||||||
|             StrnCatGrow(&FullPath, &Size, PathName, 0); |             StrnCatGrow(&FullPath, &Size, PathName, 0); | ||||||
|             if  (ShellIsDirectory(PathName) == EFI_SUCCESS) { |             if  (ShellIsDirectory(PathName) == EFI_SUCCESS) { | ||||||
|  |               if (PathName[StrLen (PathName) - 1] == '\\') { | ||||||
|  |                 // | ||||||
|  |                 // For path ending with '\', just append '*'. | ||||||
|  |                 // | ||||||
|  |                 StrnCatGrow (&FullPath, &Size, L"*", 0); | ||||||
|  |               } else if (PathName[StrLen (PathName) - 1] == '*') { | ||||||
|  |                 // | ||||||
|  |                 // For path ending with '*', do nothing. | ||||||
|  |                 // | ||||||
|  |               } else { | ||||||
|  |                 // | ||||||
|  |                 // Otherwise, append '\*' to directory name. | ||||||
|  |                 // | ||||||
|                 StrnCatGrow (&FullPath, &Size, L"\\*", 0); |                 StrnCatGrow (&FullPath, &Size, L"\\*", 0); | ||||||
|               } |               } | ||||||
|             } |             } | ||||||
|  |           } | ||||||
|         } else { |         } else { | ||||||
|           ASSERT(FullPath == NULL); |           ASSERT(FullPath == NULL); | ||||||
|           StrnCatGrow(&FullPath, NULL, L"*", 0); |           StrnCatGrow(&FullPath, NULL, L"*", 0); | ||||||
| @@ -568,7 +580,7 @@ ShellCommandRunLs ( | |||||||
|             (INT16)(TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:TheTime.TimeZone) |             (INT16)(TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:TheTime.TimeZone) | ||||||
|            ); |            ); | ||||||
|           if (ShellStatus == SHELL_NOT_FOUND) { |           if (ShellStatus == SHELL_NOT_FOUND) { | ||||||
|             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_FILES), gShellLevel2HiiHandle); |             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LS_FILE_NOT_FOUND), gShellLevel2HiiHandle); | ||||||
|           } else if (ShellStatus == SHELL_INVALID_PARAMETER) { |           } else if (ShellStatus == SHELL_INVALID_PARAMETER) { | ||||||
|             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle); |             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle); | ||||||
|           } else if (ShellStatus == SHELL_ABORTED) { |           } else if (ShellStatus == SHELL_ABORTED) { | ||||||
|   | |||||||
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user