From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (EUR02-VE1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.1504.1571573315251344544 for ; Sun, 20 Oct 2019 05:08:36 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@outlook.com header.s=selector1 header.b=K220h3/3; spf=softfail (domain: outlook.com, ip: , mailfrom: marvin.haeuser@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UNUCEvOXrinWD2P49W8fY19GeALbdwLVslwQZyNGQOaHkc+IQbx7y0cH40/ilyAlkxICs/8/x6V4FW4uUBYHMOuGdlzSiAGEJaps3pxEPU5L2130GHWtV7zfEL3KgZBUOHHBrzUaOJ9nAozXGl4uu7qWPKtZK18RsJSgDuqbVr8hTYBDGc0HhLt8kJM8xhuQ5r1UWynH0GJKMKnEiSu18ik0FZC1c5WcDJLHObmRPdBuw50fM4FXGDeVMMJ22rPGO/kGa+/WFy5p+LPH5cNulG3K6L+SwPSiOu1REuwJBEMSPavbS5ENEv5TQmGx3lxTWyCsmzwxY3BlIm9cOX6vzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=B3fo6Vw8Vr7S+VDPsp2leCAP5euon+k1tGQ3twZh0N4=; b=k2nWb7azfbQBGX+PQ3G62qwXIkbTgnXu67sWejxRIkG74OWGtqTTUyRgs7tX3nT4r7tFrvwyJyLlfL61oNP71UJiFtm6h/Fm5kavEHWi68IIGgVyg5ixajgB2m8Fgj4YpmB2WMyi7BHxLjNxo+i4U8POptOmTONEMCheFtPktONOqd587u5nPdOiLJZwv1tDpfsargiagzYNs8l2O9s2WuLsDU4UWI2ex1gMq9kdSy6AkXTWz3OIjBO6hACi4bV0Xh1cgTS9m91cEMnFZkfSIWdVhKrgCx4z/DhlTST8aG3myFGpI0zdR+/1uqt5WCl/RokzbwxD/J5s+/zIgbiMRQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none 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:X-MS-Exchange-SenderADCheck; bh=B3fo6Vw8Vr7S+VDPsp2leCAP5euon+k1tGQ3twZh0N4=; b=K220h3/3nzeS6RbQiZ3MjMpXA+sVRK50umQW78FgEgn+uKYt09SgOGbjaQl6ozktuGqx7X+/1ojF3QIGuzJsOEPcuzPR+tIrLmjXqzQQajCJGoCqG4PgxTaM73+cUML+63oLGuI23cco8QJS3iCAVkqNmQ5c5weWX+OI+rSzUHSekSUEtLOFgTS2ibdTcbEtEuaNyq4qL3oU1/njh7YPN56XywlG6F8kZQQjGg3i8vjfHQQp+FGs00+/Tfz+mIbB7RLmxTLNmCeAzWZs2r0OPtr+9tI1WmOsPWtQm4XI2bcTvV2B41YqGs2WZT6GJYL9a728kWpmdQmdbxc60bPpxg== Received: from VE1EUR02FT003.eop-EUR02.prod.protection.outlook.com (10.152.12.55) by VE1EUR02HT150.eop-EUR02.prod.protection.outlook.com (10.152.13.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2367.14; Sun, 20 Oct 2019 12:08:33 +0000 Received: from DB7PR07MB4917.eurprd07.prod.outlook.com (10.152.12.58) by VE1EUR02FT003.mail.protection.outlook.com (10.152.12.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2367.14 via Frontend Transport; Sun, 20 Oct 2019 12:08:33 +0000 Received: from DB7PR07MB4917.eurprd07.prod.outlook.com ([fe80::1b8:f59a:96de:82ef]) by DB7PR07MB4917.eurprd07.prod.outlook.com ([fe80::1b8:f59a:96de:82ef%3]) with mapi id 15.20.2367.021; Sun, 20 Oct 2019 12:08:33 +0000 From: =?iso-8859-1?Q?Marvin_H=E4user?= To: "devel@edk2.groups.io" CC: "vit9696@protonmail.com" , Ray Ni , Zhichao Gao Subject: [PATCH] ShellPkg/Ls: Return empty content for all empty folders Thread-Topic: [PATCH] ShellPkg/Ls: Return empty content for all empty folders Thread-Index: AQHVhz8YYOklQdM3n0O8Sde/0lsI9g== Date: Sun, 20 Oct 2019 12:08:33 +0000 Message-ID: References: In-Reply-To: Accept-Language: de-DE, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM0PR01CA0052.eurprd01.prod.exchangelabs.com (2603:10a6:208:e6::29) To DB7PR07MB4917.eurprd07.prod.outlook.com (2603:10a6:10:5f::30) x-incomingtopheadermarker: OriginalChecksum:5AC81D680DB881777F8312BE18D2E5321DCF1D442D42511585DDAA7920FF380E;UpperCasedChecksum:0ABAB2DD040D34D7CCC60D246E20E776CA3ABAAEB015C2F1160EDCD751098719;SizeAsReceived:7753;Count:51 x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0.windows.1 x-tmn: [Bxk2i+US9dJ4RpM36p3M/BFI/PA3EItW] x-microsoft-original-message-id: <3b8072fcdb50ae2b6cf53be633d30e052841df73.1571572996.git.mhaeuser@outlook.de> x-ms-publictraffictype: Email x-incomingheadercount: 51 x-eopattributedmessage: 0 x-ms-traffictypediagnostic: VE1EUR02HT150: x-ms-exchange-purlcount: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: y6+v26GV34zZ0mB2nbNNJxnJyqaZnFZQEZ7YyqZJkSpQlAPDh8Zry+3GzKHUqd/ACgac063O2jVYK/CvtXOztH/UY+0hSMeGZaE7MhUSQtrXslZbIywLKqGkEhzEKVPoYKQVBwY/K8rPhOaQoPsFE78Yu9mC/uHs9lYFak/g9majEQFm6hVurr9YsUWl+MPEHSB/enNthAWAog2oyO5raJAVimioOXdikjKBxGMWntc= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 4fbe4193-47d0-4928-575b-08d755563a69 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Oct 2019 12:08:33.5877 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR02HT150 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable From: Marvin Haeuser REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2296 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. Cc: Ray Ni Cc: Zhichao Gao 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 1a65f60c3b44..da2b1acab47c 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c @@ -417,6 +417,8 @@ FileTimeToLocalTime ( @param[in] Found Set to TRUE, if anyone were found.=0D @param[in] Count The count of bits enabled in Attribs.=0D @param[in] TimeZone The current time zone offset.=0D + @param[in] ListUnfiltered TRUE to request listing the directory contents= =0D + unfiltered.=0D =0D @retval SHELL_SUCCESS the printing was sucessful.=0D **/=0D @@ -429,7 +431,8 @@ PrintLsOutput( IN CONST CHAR16 *SearchString,=0D IN BOOLEAN *Found,=0D IN CONST UINTN Count,=0D - IN CONST INT16 TimeZone=0D + IN CONST INT16 TimeZone,=0D + IN CONST BOOLEAN ListUnfiltered=0D )=0D {=0D EFI_STATUS Status;=0D @@ -555,7 +558,7 @@ PrintLsOutput( HeaderPrinted =3D TRUE;=0D }=0D =0D - if (!Sfo && ShellStatus !=3D SHELL_ABORTED) {=0D + if (!Sfo && ShellStatus !=3D SHELL_ABORTED && HeaderPrinted) {=0D PrintNonSfoFooter(FileCount, FileSize, DirCount);=0D }=0D }=0D @@ -602,7 +605,8 @@ PrintLsOutput( SearchString,=0D &FoundOne,=0D Count,=0D - TimeZone);=0D + TimeZone,=0D + FALSE);=0D =0D //=0D // Since it's running recursively, we have to break immediately = when returned SHELL_ABORTED=0D @@ -619,7 +623,21 @@ PrintLsOutput( ShellCloseFileMetaArg(&ListHead);=0D =0D if (Found =3D=3D NULL && !FoundOne) {=0D - return (SHELL_NOT_FOUND);=0D + if (ListUnfiltered) {=0D + //=0D + // When running "ls" without any filtering request, avoid outputing= =0D + // "File not found" when the directory is entirely empty, but print= =0D + // header and footer stating "0 File(s), 0 Dir(s)".=0D + //=0D + if (!Sfo) {=0D + PrintNonSfoHeader (RootPath);=0D + if (ShellStatus !=3D SHELL_ABORTED) {=0D + PrintNonSfoFooter (FileCount, FileSize, DirCount);=0D + }=0D + }=0D + } else {=0D + return (SHELL_NOT_FOUND);=0D + }=0D }=0D =0D if (Found !=3D NULL) {=0D @@ -662,6 +680,7 @@ ShellCommandRunLs ( UINTN Size;=0D EFI_TIME TheTime;=0D CHAR16 *SearchString;=0D + BOOLEAN ListUnfiltered;=0D =0D Size =3D 0;=0D FullPath =3D NULL;=0D @@ -673,6 +692,7 @@ ShellCommandRunLs ( SearchString =3D NULL;=0D CurDir =3D NULL;=0D Count =3D 0;=0D + ListUnfiltered =3D FALSE;=0D =0D //=0D // initialize the shell lib (we must be in non-auto-init...)=0D @@ -768,6 +788,7 @@ ShellCommandRunLs ( ShellStatus =3D SHELL_NOT_FOUND;=0D ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), g= ShellLevel2HiiHandle, L"ls");=0D }=0D + ListUnfiltered =3D TRUE;=0D //=0D // Copy to the 2 strings for starting path and file search strin= g=0D //=0D @@ -808,6 +829,7 @@ ShellCommandRunLs ( //=0D // is listing ends with a directory, then we list all files = in that directory=0D //=0D + ListUnfiltered =3D TRUE;=0D StrnCatGrow(&SearchString, NULL, L"*", 0);=0D } else {=0D //=0D @@ -839,7 +861,8 @@ ShellCommandRunLs ( SearchString,=0D NULL,=0D Count,=0D - TheTime.TimeZone=0D + TheTime.TimeZone,=0D + ListUnfiltered=0D );=0D if (ShellStatus =3D=3D SHELL_NOT_FOUND) {=0D ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LS_FILE_NOT_FO= UND), gShellLevel2HiiHandle, L"ls", FullPath);=0D --=20 2.23.0.windows.1