diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c b/ShellPkg/Application/Shell/FileHandleWrappers.c index b3a3cfcf95..2344bbb761 100644 --- a/ShellPkg/Application/Shell/FileHandleWrappers.c +++ b/ShellPkg/Application/Shell/FileHandleWrappers.c @@ -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))) { diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c index 58c4a03613..6a298a7f06 100644 --- a/ShellPkg/Application/Shell/ShellProtocol.c +++ b/ShellPkg/Application/Shell/ShellProtocol.c @@ -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)) { // // // diff --git a/ShellPkg/Include/Library/ShellLib.h b/ShellPkg/Include/Library/ShellLib.h index 7406a56554..a6e39aea6b 100644 --- a/ShellPkg/Include/Library/ShellLib.h +++ b/ShellPkg/Include/Library/ShellLib.h @@ -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 + ); diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Attrib.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Attrib.c index 0a7b36c86e..36fb96a296 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Attrib.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Attrib.c @@ -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; } diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c index 8830e11c3a..59c573553c 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c @@ -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; } diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c index f2587f67a4..e625921b15 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c @@ -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, diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c index b92fafb94b..e41317ce89 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c @@ -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; } diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c index fa71b31296..447ebe15d5 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c @@ -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; } diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c b/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c index 6b70cc4e7e..292e80854c 100644 --- a/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c +++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c @@ -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. // diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c index fd8f58a5d0..0f605db0be 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -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); +}