public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] ShellPkg/UefiShellLevel2CommandsLib: Fix ls on entirely empty directories.
@ 2018-05-06  0:10 Marvin Häuser
  2018-05-07 18:10 ` Carsey, Jaben
  0 siblings, 1 reply; 2+ messages in thread
From: Marvin Häuser @ 2018-05-06  0:10 UTC (permalink / raw)
  To: edk2-devel@lists.01.org; +Cc: jaben.carsey@intel.com, ruiyu.ni@intel.com

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 <Marvin.Haeuser@outlook.com>
---
 ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c | 33 +++++++++++++++++---
 1 file changed, 28 insertions(+), 5 deletions(-)

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 contents
+                            unfiltered.
 
   @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 = TRUE;
     }
 
-    if (!Sfo && ShellStatus != SHELL_ABORTED) {
+    if (!Sfo && ShellStatus != SHELL_ABORTED && HeaderPrinted) {
       PrintNonSfoFooter(FileCount, FileSize, DirCount);
     }
   }
@@ -608,7 +611,8 @@ PrintLsOutput(
             SearchString,
             &FoundOne,
             Count,
-            TimeZone);
+            TimeZone,
+            FALSE);
             
           //
           // Since it's running recursively, we have to break immediately when returned SHELL_ABORTED
@@ -625,7 +629,21 @@ PrintLsOutput(
   ShellCloseFileMetaArg(&ListHead);
 
   if (Found == 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 != SHELL_ABORTED) {
+          PrintNonSfoFooter (FileCount, FileSize, DirCount);
+        }
+      }
+    } else {
+      return (SHELL_NOT_FOUND);
+    }
   }
 
   if (Found != NULL) {
@@ -668,6 +686,7 @@ ShellCommandRunLs (
   UINTN         Size;
   EFI_TIME      TheTime;
   CHAR16        *SearchString;
+  BOOLEAN       ListUnfiltered;
 
   Size                = 0;
   FullPath            = NULL;
@@ -679,6 +698,7 @@ ShellCommandRunLs (
   SearchString        = NULL;
   CurDir              = NULL;
   Count               = 0;
+  ListUnfiltered      = FALSE;
 
   //
   // initialize the shell lib (we must be in non-auto-init...)
@@ -774,6 +794,7 @@ ShellCommandRunLs (
             ShellStatus = SHELL_NOT_FOUND;
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"ls");  
           }
+          ListUnfiltered = TRUE;
           //
           // Copy to the 2 strings for starting path and file search string
           //
@@ -814,6 +835,7 @@ ShellCommandRunLs (
               //
               // is listing ends with a directory, then we list all files in that directory
               //
+              ListUnfiltered = TRUE;
               StrnCatGrow(&SearchString, NULL, L"*", 0);
             } else {
               //
@@ -845,7 +867,8 @@ ShellCommandRunLs (
             SearchString,
             NULL,
             Count,
-            TheTime.TimeZone
+            TheTime.TimeZone,
+            ListUnfiltered
            );
           if (ShellStatus == SHELL_NOT_FOUND) {
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LS_FILE_NOT_FOUND), gShellLevel2HiiHandle, L"ls", FullPath);  
-- 
2.17.0.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ShellPkg/UefiShellLevel2CommandsLib: Fix ls on entirely empty directories.
  2018-05-06  0:10 [PATCH] ShellPkg/UefiShellLevel2CommandsLib: Fix ls on entirely empty directories Marvin Häuser
@ 2018-05-07 18:10 ` Carsey, Jaben
  0 siblings, 0 replies; 2+ messages in thread
From: Carsey, Jaben @ 2018-05-07 18:10 UTC (permalink / raw)
  To: Marvin Häuser, edk2-devel@lists.01.org; +Cc: Ni, Ruiyu

Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Marvin Häuser
> Sent: Saturday, May 05, 2018 5:11 PM
> To: edk2-devel@lists.01.org
> Cc: Carsey, Jaben <jaben.carsey@intel.com>; Ni, Ruiyu <ruiyu.ni@intel.com>
> Subject: [edk2] [PATCH] ShellPkg/UefiShellLevel2CommandsLib: Fix ls on
> entirely empty directories.
> Importance: High
> 
> 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 <Marvin.Haeuser@outlook.com>
> ---
>  ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c | 33
> +++++++++++++++++---
>  1 file changed, 28 insertions(+), 5 deletions(-)
> 
> 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 contents
> +                            unfiltered.
> 
>    @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 = TRUE;
>      }
> 
> -    if (!Sfo && ShellStatus != SHELL_ABORTED) {
> +    if (!Sfo && ShellStatus != SHELL_ABORTED && HeaderPrinted) {
>        PrintNonSfoFooter(FileCount, FileSize, DirCount);
>      }
>    }
> @@ -608,7 +611,8 @@ PrintLsOutput(
>              SearchString,
>              &FoundOne,
>              Count,
> -            TimeZone);
> +            TimeZone,
> +            FALSE);
> 
>            //
>            // Since it's running recursively, we have to break immediately when
> returned SHELL_ABORTED
> @@ -625,7 +629,21 @@ PrintLsOutput(
>    ShellCloseFileMetaArg(&ListHead);
> 
>    if (Found == 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 != SHELL_ABORTED) {
> +          PrintNonSfoFooter (FileCount, FileSize, DirCount);
> +        }
> +      }
> +    } else {
> +      return (SHELL_NOT_FOUND);
> +    }
>    }
> 
>    if (Found != NULL) {
> @@ -668,6 +686,7 @@ ShellCommandRunLs (
>    UINTN         Size;
>    EFI_TIME      TheTime;
>    CHAR16        *SearchString;
> +  BOOLEAN       ListUnfiltered;
> 
>    Size                = 0;
>    FullPath            = NULL;
> @@ -679,6 +698,7 @@ ShellCommandRunLs (
>    SearchString        = NULL;
>    CurDir              = NULL;
>    Count               = 0;
> +  ListUnfiltered      = FALSE;
> 
>    //
>    // initialize the shell lib (we must be in non-auto-init...)
> @@ -774,6 +794,7 @@ ShellCommandRunLs (
>              ShellStatus = SHELL_NOT_FOUND;
>              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD),
> gShellLevel2HiiHandle, L"ls");
>            }
> +          ListUnfiltered = TRUE;
>            //
>            // Copy to the 2 strings for starting path and file search string
>            //
> @@ -814,6 +835,7 @@ ShellCommandRunLs (
>                //
>                // is listing ends with a directory, then we list all files in that directory
>                //
> +              ListUnfiltered = TRUE;
>                StrnCatGrow(&SearchString, NULL, L"*", 0);
>              } else {
>                //
> @@ -845,7 +867,8 @@ ShellCommandRunLs (
>              SearchString,
>              NULL,
>              Count,
> -            TheTime.TimeZone
> +            TheTime.TimeZone,
> +            ListUnfiltered
>             );
>            if (ShellStatus == SHELL_NOT_FOUND) {
>              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN
> (STR_LS_FILE_NOT_FOUND), gShellLevel2HiiHandle, L"ls", FullPath);
> --
> 2.17.0.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-07 18:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-06  0:10 [PATCH] ShellPkg/UefiShellLevel2CommandsLib: Fix ls on entirely empty directories Marvin Häuser
2018-05-07 18:10 ` Carsey, Jaben

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox