summaryrefslogtreecommitdiffstats
path: root/ShellPkg
diff options
context:
space:
mode:
authorMarvin Haeuser <mhaeuser@outlook.de>2019-10-20 20:08:33 +0800
committerLiming Gao <liming.gao@intel.com>2019-11-04 10:46:02 +0800
commit8d3f428109623096cb8845779cdf9dc44949b8e9 (patch)
tree55c2e7bd3d687b1d659e7beb95afeb223a7e2efb /ShellPkg
parent106369fe26579c2c97131c3dd9e7c7332a5ec575 (diff)
downloadedk2-8d3f428109623096cb8845779cdf9dc44949b8e9.tar.gz
edk2-8d3f428109623096cb8845779cdf9dc44949b8e9.tar.bz2
edk2-8d3f428109623096cb8845779cdf9dc44949b8e9.zip
ShellPkg/Ls: Return empty content for all empty folders
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2296 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 <ray.ni@intel.com> Cc: Zhichao Gao <zhichao.gao@intel.com> Signed-off-by: Marvin Haeuser <mhaeuser@outlook.de> Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
Diffstat (limited to 'ShellPkg')
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
index 1a65f60c3b..da2b1acab4 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.
@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.
**/
@@ -429,7 +431,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;
@@ -555,7 +558,7 @@ PrintLsOutput(
HeaderPrinted = TRUE;
}
- if (!Sfo && ShellStatus != SHELL_ABORTED) {
+ if (!Sfo && ShellStatus != SHELL_ABORTED && HeaderPrinted) {
PrintNonSfoFooter(FileCount, FileSize, DirCount);
}
}
@@ -602,7 +605,8 @@ PrintLsOutput(
SearchString,
&FoundOne,
Count,
- TimeZone);
+ TimeZone,
+ FALSE);
//
// Since it's running recursively, we have to break immediately when returned SHELL_ABORTED
@@ -619,7 +623,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) {
@@ -662,6 +680,7 @@ ShellCommandRunLs (
UINTN Size;
EFI_TIME TheTime;
CHAR16 *SearchString;
+ BOOLEAN ListUnfiltered;
Size = 0;
FullPath = NULL;
@@ -673,6 +692,7 @@ ShellCommandRunLs (
SearchString = NULL;
CurDir = NULL;
Count = 0;
+ ListUnfiltered = FALSE;
//
// initialize the shell lib (we must be in non-auto-init...)
@@ -768,6 +788,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
//
@@ -808,6 +829,7 @@ ShellCommandRunLs (
//
// is listing ends with a directory, then we list all files in that directory
//
+ ListUnfiltered = TRUE;
StrnCatGrow(&SearchString, NULL, L"*", 0);
} else {
//
@@ -839,7 +861,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);