mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 21:42:57 +00:00
[CMD] Add speed-optimized checks for dot-directories "." and ".." .
Adapted from PR #592 by Katayama Hirofumi MZ.
This commit is contained in:
parent
17ebc8421a
commit
23b36fc173
1 changed files with 35 additions and 22 deletions
|
@ -233,6 +233,28 @@ DirHelp(VOID)
|
||||||
ConOutResPaging(TRUE, STRING_DIR_HELP1);
|
ConOutResPaging(TRUE, STRING_DIR_HELP1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check whether this is a dot-directory "." or "..", speed-optimized */
|
||||||
|
FORCEINLINE
|
||||||
|
BOOL
|
||||||
|
IsDotDirectory(
|
||||||
|
IN LPCTSTR pszPath)
|
||||||
|
{
|
||||||
|
return ( pszPath[0] == _T('.') &&
|
||||||
|
( pszPath[1] == 0 || /* pszPath[1] == _T('\\') || */
|
||||||
|
(pszPath[1] == _T('.') && (pszPath[2] == 0 /* || pszPath[2] == _T('\\') */))
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
|
||||||
|
FORCEINLINE
|
||||||
|
BOOL
|
||||||
|
IsDotDirectoryN(
|
||||||
|
IN const TCHAR* pPath,
|
||||||
|
IN SIZE_T Length)
|
||||||
|
{
|
||||||
|
return ((Length == 1 && pPath[0] == _T('.')) ||
|
||||||
|
(Length == 2 && pPath[0] == _T('.') && pPath[1] == _T('.')));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DirReadParameters
|
* DirReadParameters
|
||||||
*
|
*
|
||||||
|
@ -822,11 +844,10 @@ getName(const TCHAR* file, TCHAR * dest)
|
||||||
INT_PTR iLen;
|
INT_PTR iLen;
|
||||||
LPTSTR end;
|
LPTSTR end;
|
||||||
|
|
||||||
/* Check for "." and ".." folders */
|
/* Check for dot-directories "." and ".." */
|
||||||
if ((_tcscmp(file, _T(".")) == 0) ||
|
if (IsDotDirectory(file))
|
||||||
(_tcscmp(file, _T("..")) == 0))
|
|
||||||
{
|
{
|
||||||
_tcscpy(dest,file);
|
_tcscpy(dest, file);
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1087,20 +1108,19 @@ DirPrintBareList(PDIRFINDINFO ptrFiles[], /* [IN] Files' Info */
|
||||||
|
|
||||||
for (i = 0; i < dwCount && !CheckCtrlBreak(BREAK_INPUT); i++)
|
for (i = 0; i < dwCount && !CheckCtrlBreak(BREAK_INPUT); i++)
|
||||||
{
|
{
|
||||||
if ((_tcscmp(ptrFiles[i]->stFindInfo.cFileName, _T(".")) == 0) ||
|
if (IsDotDirectory(ptrFiles[i]->stFindInfo.cFileName))
|
||||||
(_tcscmp(ptrFiles[i]->stFindInfo.cFileName, _T("..")) == 0))
|
|
||||||
{
|
{
|
||||||
/* at bare format we don't print "." and ".." folder */
|
/* At bare format we don't print the dot-directories "." and ".." */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (lpFlags->bRecursive)
|
if (lpFlags->bRecursive)
|
||||||
{
|
{
|
||||||
/* at recursive mode we print full path of file */
|
/* At recursive mode we print full path of file */
|
||||||
DirPrintf(lpFlags, _T("%s\\%s\n"), szCurPath, ptrFiles[i]->stFindInfo.cFileName);
|
DirPrintf(lpFlags, _T("%s\\%s\n"), szCurPath, ptrFiles[i]->stFindInfo.cFileName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* if we are not in recursive mode we print the file names */
|
/* If we are not in recursive mode we print the file names */
|
||||||
DirPrintf(lpFlags, _T("%s\n"), ptrFiles[i]->stFindInfo.cFileName);
|
DirPrintf(lpFlags, _T("%s\n"), ptrFiles[i]->stFindInfo.cFileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1376,7 +1396,7 @@ DirList(IN OUT LPTSTR szFullPath, /* [IN] The full path we are listing with tr
|
||||||
ptrStartNode->stInfo.ptrHead = NULL;
|
ptrStartNode->stInfo.ptrHead = NULL;
|
||||||
ptrNextNode = ptrStartNode;
|
ptrNextNode = ptrStartNode;
|
||||||
|
|
||||||
/* Collect the results for the current folder */
|
/* Collect the results for the current directory */
|
||||||
hSearch = FindFirstFile(szFullPath, &wfdFileInfo);
|
hSearch = FindFirstFile(szFullPath, &wfdFileInfo);
|
||||||
if (hSearch != INVALID_HANDLE_VALUE)
|
if (hSearch != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
|
@ -1561,8 +1581,7 @@ DirList(IN OUT LPTSTR szFullPath, /* [IN] The full path we are listing with tr
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
/* We search for directories other than "." and ".." */
|
/* We search for directories other than "." and ".." */
|
||||||
if ((_tcsicmp(wfdFileInfo.cFileName, _T(".")) != 0) &&
|
if (!IsDotDirectory(wfdFileInfo.cFileName) &&
|
||||||
(_tcsicmp(wfdFileInfo.cFileName, _T("..")) != 0) &&
|
|
||||||
(wfdFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
(wfdFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||||
{
|
{
|
||||||
/* Concat the path and the directory to do recursive */
|
/* Concat the path and the directory to do recursive */
|
||||||
|
@ -1572,7 +1591,7 @@ DirList(IN OUT LPTSTR szFullPath, /* [IN] The full path we are listing with tr
|
||||||
pszSubFilePart = &szSubPath[_tcslen(szSubPath)];
|
pszSubFilePart = &szSubPath[_tcslen(szSubPath)];
|
||||||
_tcscat(pszSubFilePart, pszFilePart);
|
_tcscat(pszSubFilePart, pszFilePart);
|
||||||
|
|
||||||
/* We do the same for the folder */
|
/* We do the same for the directory */
|
||||||
if (DirList(szSubPath, pszSubFilePart, lpFlags) != 0)
|
if (DirList(szSubPath, pszSubFilePart, lpFlags) != 0)
|
||||||
{
|
{
|
||||||
FindClose(hRecSearch);
|
FindClose(hRecSearch);
|
||||||
|
@ -1660,9 +1679,7 @@ ResolvePattern(
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Ignore the special "." and ".." directories that are correctly handled */
|
/* Ignore the special "." and ".." directories that are correctly handled */
|
||||||
if ((pNextDir - pCurDir == 0) ||
|
if ((pNextDir - pCurDir == 0) || IsDotDirectoryN(pCurDir, pNextDir - pCurDir))
|
||||||
(pNextDir - pCurDir == 1 && pCurDir[0] == _T('.')) ||
|
|
||||||
(pNextDir - pCurDir == 2 && pCurDir[0] == _T('.') && pCurDir[1] == _T('.')))
|
|
||||||
{
|
{
|
||||||
/* Found such a directory, ignore */
|
/* Found such a directory, ignore */
|
||||||
++pNextDir;
|
++pNextDir;
|
||||||
|
@ -1758,9 +1775,7 @@ ResolvePattern(
|
||||||
ASSERT(pszFullPath[_tcslen(pszFullPath)-1] == _T('\\'));
|
ASSERT(pszFullPath[_tcslen(pszFullPath)-1] == _T('\\'));
|
||||||
|
|
||||||
/* Anything NOT being "." or ".." (the special directories) must be fully restored */
|
/* Anything NOT being "." or ".." (the special directories) must be fully restored */
|
||||||
if (*pNextDir &&
|
if (*pNextDir && !IsDotDirectory(pNextDir))
|
||||||
(_tcsicmp(pNextDir, _T(".")) != 0) &&
|
|
||||||
(_tcsicmp(pNextDir, _T("..")) != 0))
|
|
||||||
{
|
{
|
||||||
pszPatternPart = &pszFullPath[_tcslen(pszFullPath)];
|
pszPatternPart = &pszFullPath[_tcslen(pszFullPath)];
|
||||||
_tcscpy(pszPatternPart, pNextDir);
|
_tcscpy(pszPatternPart, pNextDir);
|
||||||
|
@ -1777,9 +1792,7 @@ ResolvePattern(
|
||||||
TRACE("pszPatternPart: %S is DIFFERENT from file criterion: %S\n", pszPatternPart, pNextDir);
|
TRACE("pszPatternPart: %S is DIFFERENT from file criterion: %S\n", pszPatternPart, pNextDir);
|
||||||
|
|
||||||
/* Anything NOT being "." or ".." (the special directories) must be fully restored */
|
/* Anything NOT being "." or ".." (the special directories) must be fully restored */
|
||||||
if (*pNextDir &&
|
if (*pNextDir && !IsDotDirectory(pNextDir))
|
||||||
(_tcsicmp(pNextDir, _T(".")) != 0) &&
|
|
||||||
(_tcsicmp(pNextDir, _T("..")) != 0))
|
|
||||||
{
|
{
|
||||||
/* Restore the correct file criterion */
|
/* Restore the correct file criterion */
|
||||||
_tcscpy(pszPatternPart, pNextDir);
|
_tcscpy(pszPatternPart, pNextDir);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue