ShellPkg/UefiShellLib: Add IsDotOrDotDot() function

Replace existing checks against L"." and L".." by
a named function.

No functional change.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
This commit is contained in:
Pierre Gondois 2026-04-03 09:18:45 +02:00 committed by mergify[bot]
parent 4afe895a77
commit 420dab0b24
10 changed files with 38 additions and 19 deletions

View file

@ -403,7 +403,7 @@ CreateTabCompletionList (
}
for (FileInfo = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link); !IsNull (&FileList->Link, &FileInfo->Link); ) {
if (((StrCmp (FileInfo->FileName, L".") == 0) || (StrCmp (FileInfo->FileName, L"..") == 0)) ||
if (IsDotOrDotDot (FileInfo->FileName) ||
((((InputString[0] == L'c') || (InputString[0] == L'C')) && ((InputString[1] == L'd') || (InputString[1] == L'D'))) &&
(ShellIsDirectory (FileInfo->FullName) != EFI_SUCCESS)))
{

View file

@ -2533,10 +2533,7 @@ ShellSearchHandle (
//
// don't open the . and .. directories
//
if ( (StrCmp (ShellInfoNode->FileName, L".") != 0)
&& (StrCmp (ShellInfoNode->FileName, L"..") != 0)
)
{
if (!IsDotOrDotDot (ShellInfoNode->FileName)) {
//
//
//

View file

@ -1436,3 +1436,15 @@ ShellPrintHelp (
IN CONST CHAR16 *SectionToGetHelpOn,
IN BOOLEAN PrintCommandText
);
/** Check whther the input name is L"." or L"..".
@param[in] Name Name to check.
@return TRUE if the input name matches L"." or L"..".
**/
BOOLEAN
EFIAPI
IsDotOrDotDot (
CONST CHAR16 *Name
);

View file

@ -196,7 +196,7 @@ MainCmdAttrib (
//
// skip the directory traversing stuff...
//
if ((StrCmp (FileNode->FileName, L".") == 0) || (StrCmp (FileNode->FileName, L"..") == 0)) {
if (IsDotOrDotDot (FileNode->FileName)) {
continue;
}

View file

@ -366,7 +366,7 @@ ValidateAndCopyFiles (
//
// skip the directory traversing stuff...
//
if ((StrCmp (Node->FileName, L".") == 0) || (StrCmp (Node->FileName, L"..") == 0)) {
if (IsDotOrDotDot (Node->FileName)) {
continue;
}
@ -429,7 +429,7 @@ ValidateAndCopyFiles (
//
// skip the directory traversing stuff...
//
if ((StrCmp (Node->FileName, L".") == 0) || (StrCmp (Node->FileName, L"..") == 0)) {
if (IsDotOrDotDot (Node->FileName)) {
continue;
}

View file

@ -631,9 +631,7 @@ PrintLsOutput (
// recurse on any directory except the traversing ones...
//
if ( ((Node->Info->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY)
&& (StrCmp (Node->FileName, L".") != 0)
&& (StrCmp (Node->FileName, L"..") != 0)
)
&& !IsDotOrDotDot (Node->FileName))
{
ShellStatus = PrintLsOutput (
Rec,

View file

@ -639,7 +639,7 @@ ValidateAndMoveFiles (
//
// skip the directory traversing stuff...
//
if ((StrCmp (Node->FileName, L".") == 0) || (StrCmp (Node->FileName, L"..") == 0)) {
if (IsDotOrDotDot (Node->FileName)) {
continue;
}

View file

@ -120,7 +120,7 @@ CascadeDelete (
//
// skip the directory traversing stuff...
//
if ((StrCmp (Node2->FileName, L".") == 0) || (StrCmp (Node2->FileName, L"..") == 0)) {
if (IsDotOrDotDot (Node2->FileName)) {
continue;
}
@ -168,7 +168,7 @@ CascadeDelete (
}
}
if (!((StrCmp (Node->FileName, L".") == 0) || (StrCmp (Node->FileName, L"..") == 0))) {
if (!IsDotOrDotDot (Node->FileName)) {
//
// now delete the current node...
//
@ -336,7 +336,7 @@ MainCmdRm (
//
// skip the directory traversing stuff...
//
if ((StrCmp (Node->FileName, L".") == 0) || (StrCmp (Node->FileName, L"..") == 0)) {
if (IsDotOrDotDot (Node->FileName)) {
continue;
}

View file

@ -117,10 +117,7 @@ DoTouchByHandle (
; Walker = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Walker->Link)
)
{
if ( (StrCmp (Walker->FileName, L".") != 0)
&& (StrCmp (Walker->FileName, L"..") != 0)
)
{
if (!IsDotOrDotDot (Walker->FileName)) {
//
// Open the file since we need that handle.
//

View file

@ -4604,3 +4604,18 @@ InternalShellStripQuotes (
return EFI_SUCCESS;
}
/** Check whther the input name is L"." or L"..".
@param[in] Name Name to check.
@return TRUE if the input name matches L"." or L"..".
**/
BOOLEAN
EFIAPI
IsDotOrDotDot (
CONST CHAR16 *Name
)
{
return (StrCmp (Name, L".") == 0) || (StrCmp (Name, L"..") == 0);
}