From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.92.68.90; helo=eur02-he1-obe.outbound.protection.outlook.com; envelope-from=marvin.haeuser@outlook.com; receiver=edk2-devel@lists.01.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-oln040092068090.outbound.protection.outlook.com [40.92.68.90]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6ED10203BB54B for ; Sat, 5 May 2018 17:10:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=SHpkU5Dd9ShTTxkHv49KrLd093wtsfb9Jq9UaAAdoys=; b=ORMtSx4WfMScgRelrSn788OqsSH+4958sxSgUdqd02kv93O0LTt9Bus8V+t2LY1paCiq8zp0X1gb4pEUkB6g2Hx+VLyVE452PU5AFtaCBw7XMa+QQSeCCKV1yWMfGfugWmnUo0JPykSBWGQbYEs78qyO5yRCvntJ/pmG0j0+OPBAfxG9qL9nfckShNuLGqM1rK31gfxk8RZ4HNmtHv2Pb68ZC43c++kZ2jzEL2DRVDB2Vzj2NlDLsLvJ82a60cD+s5/w5qGqMC4aogCprhQfxT+pRXpvDd9gzWGdRiNLhErCdx+67WNaTYzzU5sdMjveKjOS/M/1fM+h6SIaXvEWIQ== Received: from HE1EUR02FT027.eop-EUR02.prod.protection.outlook.com (10.152.10.52) by HE1EUR02HT056.eop-EUR02.prod.protection.outlook.com (10.152.10.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.715.13; Sun, 6 May 2018 00:10:38 +0000 Received: from VI1PR0801MB1790.eurprd08.prod.outlook.com (10.152.10.56) by HE1EUR02FT027.mail.protection.outlook.com (10.152.10.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.20.735.16 via Frontend Transport; Sun, 6 May 2018 00:10:38 +0000 Received: from VI1PR0801MB1790.eurprd08.prod.outlook.com ([fe80::7c79:584b:2e12:783e]) by VI1PR0801MB1790.eurprd08.prod.outlook.com ([fe80::7c79:584b:2e12:783e%17]) with mapi id 15.20.0715.024; Sun, 6 May 2018 00:10:38 +0000 From: =?iso-8859-1?Q?Marvin_H=E4user?= To: "edk2-devel@lists.01.org" CC: "jaben.carsey@intel.com" , "ruiyu.ni@intel.com" Thread-Topic: [PATCH] ShellPkg/UefiShellLevel2CommandsLib: Fix ls on entirely empty directories. Thread-Index: AQHT5M6pg3BVRnFD9EOQ2U7wFzLsAw== Date: Sun, 6 May 2018 00:10:38 +0000 Message-ID: Accept-Language: de-DE, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM5PR0701CA0057.eurprd07.prod.outlook.com (2603:10a6:203:2::19) To VI1PR0801MB1790.eurprd08.prod.outlook.com (2603:10a6:800:5b::15) x-incomingtopheadermarker: OriginalChecksum:90F17F815D0884659FC23565ED8BD54668162832E499A343B12D4FF025E09B7D; UpperCasedChecksum:E5C3FB01312BB781342C46B9AA20D0964D8EC6281685300F466B483B80D05D8C; SizeAsReceived:7514; Count:48 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [QIqqwd3cUExDAJC6QBkEdVCj8MT1941g] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; HE1EUR02HT056; 7:yOPwTXxNGL6Rucq/xWCSpZ4PzUtWEStdO3GXAkXxyCvKJSNJBfN6UuL1/I/ab95QsbjFRyyOYNTOoBdcQyahwABplfYi4L9aoYX/uIp83uLs97aPVHoVDjvVPWRp2TeQGstm/luh+d7XqcKxTsotl1HhlSNXgTLL0SuC5IFYKMk1crmYVkl7YBGKn4YJwEVxoaaG3d372Xjh4NmzYRjTevm6ZUa4VZW+nFU8S+2FbjPSpzFKPFi1CzAMaCXNQbvC x-incomingheadercount: 48 x-eopattributedmessage: 0 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(2017031322404)(1603101448)(1601125374)(1701031045); SRVR:HE1EUR02HT056; x-ms-traffictypediagnostic: HE1EUR02HT056: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(444000031); SRVR:HE1EUR02HT056; BCL:0; PCL:0; RULEID:; SRVR:HE1EUR02HT056; x-forefront-prvs: 06640999CA x-forefront-antispam-report: SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:HE1EUR02HT056; H:VI1PR0801MB1790.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:; x-microsoft-antispam-message-info: hPida+JmCrZZz0vuSWxSm8B3r/Z92/WflNSRD1fpp1bG2/khJYlov5DsbF6knxQWaE+AXYQuNexzrE+0RBFzcwS76XlLb38wo5FWdHASvzKl+2lGeFTCQrQm3otkPMS28jglozq+F+eiAnhnxWo6fpXlD39xhcPZLcNKsCTsWUFqd3BYjF6OY+4TjFmYn8lc MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 861d0b78-6ba5-4b49-056c-08d5b2e5cc0b X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 7181d4b0-87d6-4f4e-ba33-0d3746212cec X-MS-Exchange-CrossTenant-Network-Message-Id: 861d0b78-6ba5-4b49-056c-08d5b2e5cc0b X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 7181d4b0-87d6-4f4e-ba33-0d3746212cec X-MS-Exchange-CrossTenant-originalarrivaltime: 06 May 2018 00:10:38.8322 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1EUR02HT056 Subject: [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: Sun, 06 May 2018 00:10:42 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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. 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(-) diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Li= brary/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 contents + 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 immediately = 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 outputing + // "File not found" when the directory is entirely empty, but print + // 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), g= ShellLevel2HiiHandle, L"ls"); =20 } + ListUnfiltered =3D TRUE; // // Copy to the 2 strings for starting path and file search strin= g // @@ -814,6 +835,7 @@ ShellCommandRunLs ( // // is listing ends with a directory, then we list all files = 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_FO= UND), gShellLevel2HiiHandle, L"ls", FullPath); =20 --=20 2.17.0.windows.1