From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id EBE2F20961085 for ; Mon, 7 May 2018 11:10:44 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 May 2018 11:10:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,375,1520924400"; d="scan'208";a="48961506" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga003.jf.intel.com with ESMTP; 07 May 2018 11:10:42 -0700 Received: from FMSMSX109.amr.corp.intel.com (10.18.116.9) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 7 May 2018 11:10:42 -0700 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.228]) by FMSMSX109.amr.corp.intel.com ([169.254.15.12]) with mapi id 14.03.0319.002; Mon, 7 May 2018 11:10:42 -0700 From: "Carsey, Jaben" To: =?iso-8859-1?Q?Marvin_H=E4user?= , "edk2-devel@lists.01.org" CC: "Ni, Ruiyu" Thread-Topic: [PATCH] ShellPkg/UefiShellLevel2CommandsLib: Fix ls on entirely empty directories. Thread-Index: AQHT5M6pg3BVRnFD9EOQ2U7wFzLsA6Qkk8eg Date: Mon, 7 May 2018 18:10:41 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYWRmMjhkNjAtNTRiZi00Mzc1LWFmMGYtOTBjMjg2OTllZDE5IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6IkhMa2hkZlFCYWg1bndMa2g3dmhmSTAxV055TElUaXdiSk45aTA4dnU4K1k9In0= x-ctpclassification: CTP_NT x-originating-ip: [10.1.200.106] MIME-Version: 1.0 Subject: Re: [PATCH] ShellPkg/UefiShellLevel2CommandsLib: Fix ls on entirely empty directories. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 May 2018 18:10:45 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jaben Carsey > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Marvin H=E4user > Sent: Saturday, May 05, 2018 5:11 PM > To: edk2-devel@lists.01.org > Cc: Carsey, Jaben ; Ni, Ruiyu > Subject: [edk2] [PATCH] ShellPkg/UefiShellLevel2CommandsLib: Fix ls on > entirely empty directories. > Importance: High >=20 > Currently, when 'ls' is run on an entirely empty directory (this > includes not having '.' and '..'), the output is always 'File not > found'. For when not filtering its children, this patch rather > displays the usual header and footer. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Marvin Haeuser > --- > ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c | 33 > +++++++++++++++++--- > 1 file changed, 28 insertions(+), 5 deletions(-) >=20 > diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c > b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c > index 7d2e15f5206b..324dcb6091c8 100644 > --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c > +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c > @@ -423,6 +423,8 @@ FileTimeToLocalTime ( > @param[in] Found Set to TRUE, if anyone were found. > @param[in] Count The count of bits enabled in Attribs. > @param[in] TimeZone The current time zone offset. > + @param[in] ListUnfiltered TRUE to request listing the directory conten= ts > + unfiltered. >=20 > @retval SHELL_SUCCESS the printing was sucessful. > **/ > @@ -435,7 +437,8 @@ PrintLsOutput( > IN CONST CHAR16 *SearchString, > IN BOOLEAN *Found, > IN CONST UINTN Count, > - IN CONST INT16 TimeZone > + IN CONST INT16 TimeZone, > + IN CONST BOOLEAN ListUnfiltered > ) > { > EFI_STATUS Status; > @@ -561,7 +564,7 @@ PrintLsOutput( > HeaderPrinted =3D TRUE; > } >=20 > - if (!Sfo && ShellStatus !=3D SHELL_ABORTED) { > + if (!Sfo && ShellStatus !=3D SHELL_ABORTED && HeaderPrinted) { > PrintNonSfoFooter(FileCount, FileSize, DirCount); > } > } > @@ -608,7 +611,8 @@ PrintLsOutput( > SearchString, > &FoundOne, > Count, > - TimeZone); > + TimeZone, > + FALSE); >=20 > // > // Since it's running recursively, we have to break immediatel= y when > returned SHELL_ABORTED > @@ -625,7 +629,21 @@ PrintLsOutput( > ShellCloseFileMetaArg(&ListHead); >=20 > if (Found =3D=3D NULL && !FoundOne) { > - return (SHELL_NOT_FOUND); > + if (ListUnfiltered) { > + // > + // When running "ls" without any filtering request, avoid outputin= g > + // "File not found" when the directory is entirely empty, but prin= t > + // header and footer stating "0 File(s), 0 Dir(s)". > + // > + if (!Sfo) { > + PrintNonSfoHeader (RootPath); > + if (ShellStatus !=3D SHELL_ABORTED) { > + PrintNonSfoFooter (FileCount, FileSize, DirCount); > + } > + } > + } else { > + return (SHELL_NOT_FOUND); > + } > } >=20 > if (Found !=3D NULL) { > @@ -668,6 +686,7 @@ ShellCommandRunLs ( > UINTN Size; > EFI_TIME TheTime; > CHAR16 *SearchString; > + BOOLEAN ListUnfiltered; >=20 > Size =3D 0; > FullPath =3D NULL; > @@ -679,6 +698,7 @@ ShellCommandRunLs ( > SearchString =3D NULL; > CurDir =3D NULL; > Count =3D 0; > + ListUnfiltered =3D FALSE; >=20 > // > // initialize the shell lib (we must be in non-auto-init...) > @@ -774,6 +794,7 @@ ShellCommandRunLs ( > ShellStatus =3D SHELL_NOT_FOUND; > ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), > gShellLevel2HiiHandle, L"ls"); > } > + ListUnfiltered =3D TRUE; > // > // Copy to the 2 strings for starting path and file search str= ing > // > @@ -814,6 +835,7 @@ ShellCommandRunLs ( > // > // is listing ends with a directory, then we list all file= s in that directory > // > + ListUnfiltered =3D TRUE; > StrnCatGrow(&SearchString, NULL, L"*", 0); > } else { > // > @@ -845,7 +867,8 @@ ShellCommandRunLs ( > SearchString, > NULL, > Count, > - TheTime.TimeZone > + TheTime.TimeZone, > + ListUnfiltered > ); > if (ShellStatus =3D=3D SHELL_NOT_FOUND) { > ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN > (STR_LS_FILE_NOT_FOUND), gShellLevel2HiiHandle, L"ls", FullPath); > -- > 2.17.0.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel