From 58b7301ec9fc8df2b3955b1c04d304730538ed27 Mon Sep 17 00:00:00 2001 From: Chris Phillips Date: Fri, 18 Oct 2013 18:53:16 +0000 Subject: [PATCH] =?utf8?q?ShellPkg:=20Fixes=20for=20the=20=E2=80=98ls?= =?utf8?q?=E2=80=99=20command:=20-=20Better=20output=20to=20print=20header?= =?utf8?q?=20and=20file=20not=20found=20text=20-=20Fix=20file=20attribute?= =?utf8?q?=20argument=20handling=20-=20Fix=20so=20path=20ending=20with=20?= =?utf8?q?=E2=80=98\=E2=80=99=20or=20=E2=80=98*=E2=80=99=20is=20handled=20?= =?utf8?q?correctly?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Chris Phillips reviewed-by: Jaben Carsey git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14786 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Library/UefiShellLevel2CommandsLib/Ls.c | 84 ++++++++++-------- .../UefiShellLevel2CommandsLib.uni | Bin 111572 -> 111846 bytes 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c index 55267a467a..4d0a1563e3 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c @@ -1,6 +1,7 @@ /** @file 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.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -72,6 +73,26 @@ PrintLsOutput( 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); if (EFI_ERROR(Status)) { 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) ; !IsNull(&ListHead->Link, &Node->Link) ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link) @@ -230,21 +232,17 @@ PrintLsOutput( ){ continue; } - } else if (Attribs != EFI_FILE_VALID_ATTR) { - if (Count == 1) { - // - // the bit must match - // - if ( (Node->Info->Attribute & Attribs) != Attribs) { - continue; - } - } else { - // - // exact match on all bits - // - if ( (Node->Info->Attribute|EFI_FILE_ARCHIVE) != (Attribs|EFI_FILE_ARCHIVE)) { - continue; - } + } else if ((Attribs != EFI_FILE_VALID_ATTR) || + (Count == 5)) { + // + // 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) { + continue; } } @@ -543,7 +541,21 @@ ShellCommandRunLs ( ASSERT((FullPath == NULL && Size == 0) || (FullPath != NULL)); StrnCatGrow(&FullPath, &Size, PathName, 0); if (ShellIsDirectory(PathName) == EFI_SUCCESS) { - StrnCatGrow(&FullPath, &Size, L"\\*", 0); + 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); + } } } } else { @@ -568,7 +580,7 @@ ShellCommandRunLs ( (INT16)(TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:TheTime.TimeZone) ); 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) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle); } else if (ShellStatus == SHELL_ABORTED) { diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni index 08372d5ba36452e71fa8f2fe76b39a039dfd4111..f0991507c402826c6443005ed6d95312cc44e14d 100644 GIT binary patch delta 142 zcmcceobB05wh0d5h786G3Je|$sSM=|IY6=m2z40(7!nzh8M1+75km@4-UTRA2E;iG z`3waNxj!Xm!_ delta 21 dcmaF%lI_ZKwh0a!4_ydsRtny(6wG)e5deO33Pk__ -- 2.39.2