mirror of
https://github.com/reactos/reactos.git
synced 2025-02-21 16:04:57 +00:00
Víctor Martínez Calvo <vicmarcal AT hotmail DOT com>
- Fix dir command behavior for files without extension. - See issue #3968 for more details. svn path=/trunk/; revision=38746
This commit is contained in:
parent
0c4b617c16
commit
2b06cfc0ef
1 changed files with 55 additions and 45 deletions
|
@ -1516,21 +1516,22 @@ QsortFiles(LPWIN32_FIND_DATA ptrArray[], /* [IN/OUT] The array with file info po
|
||||||
static INT
|
static INT
|
||||||
DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
DirList(LPTSTR szPath, /* [IN] The path that dir starts */
|
||||||
LPDIRSWITCHFLAGS lpFlags) /* [IN] The flags of the listing */
|
LPDIRSWITCHFLAGS lpFlags) /* [IN] The flags of the listing */
|
||||||
{
|
{
|
||||||
|
BOOL fPoint; /* If szPath is a file with extension fPoint will be True*/
|
||||||
HANDLE hSearch; /* The handle of the search */
|
HANDLE hSearch; /* The handle of the search */
|
||||||
HANDLE hRecSearch; /* The handle for searching recursivly */
|
HANDLE hRecSearch; /* The handle for searching recursivly */
|
||||||
WIN32_FIND_DATA wfdFileInfo; /* The info of file that found */
|
WIN32_FIND_DATA wfdFileInfo; /* The info of file that found */
|
||||||
LPWIN32_FIND_DATA * ptrFileArray; /* An array of pointers with all the files */
|
LPWIN32_FIND_DATA * ptrFileArray; /* An array of pointers with all the files */
|
||||||
PDIRFINDLISTNODE ptrStartNode; /* The pointer to the first node */
|
PDIRFINDLISTNODE ptrStartNode; /* The pointer to the first node */
|
||||||
PDIRFINDLISTNODE ptrNextNode; /* A pointer used for relatives refernces */
|
PDIRFINDLISTNODE ptrNextNode; /* A pointer used for relatives refernces */
|
||||||
TCHAR szFullPath[MAX_PATH]; /* The full path that we are listing with trailing \ */
|
TCHAR szFullPath[MAX_PATH]; /* The full path that we are listing with trailing \ */
|
||||||
TCHAR szSubPath[MAX_PATH];
|
TCHAR szSubPath[MAX_PATH];
|
||||||
LPTSTR pszFilePart;
|
LPTSTR pszFilePart;
|
||||||
DWORD dwCount; /* A counter of files found in directory */
|
DWORD dwCount; /* A counter of files found in directory */
|
||||||
DWORD dwCountFiles; /* Counter for files */
|
DWORD dwCountFiles; /* Counter for files */
|
||||||
DWORD dwCountDirs; /* Counter for directories */
|
DWORD dwCountDirs; /* Counter for directories */
|
||||||
ULARGE_INTEGER u64CountBytes; /* Counter for bytes */
|
ULARGE_INTEGER u64CountBytes; /* Counter for bytes */
|
||||||
ULARGE_INTEGER u64Temp; /* A temporary counter */
|
ULARGE_INTEGER u64Temp; /* A temporary counter */
|
||||||
|
|
||||||
/* Initialize Variables */
|
/* Initialize Variables */
|
||||||
ptrStartNode = NULL;
|
ptrStartNode = NULL;
|
||||||
|
@ -1539,6 +1540,7 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */
|
||||||
dwCountFiles = 0;
|
dwCountFiles = 0;
|
||||||
dwCountDirs = 0;
|
dwCountDirs = 0;
|
||||||
u64CountBytes.QuadPart = 0;
|
u64CountBytes.QuadPart = 0;
|
||||||
|
fPoint= FALSE;
|
||||||
|
|
||||||
/* Create szFullPath */
|
/* Create szFullPath */
|
||||||
if (GetFullPathName(szPath, sizeof(szFullPath) / sizeof(TCHAR), szFullPath, &pszFilePart) == 0)
|
if (GetFullPathName(szPath, sizeof(szFullPath) / sizeof(TCHAR), szFullPath, &pszFilePart) == 0)
|
||||||
|
@ -1567,66 +1569,74 @@ ULARGE_INTEGER u64Temp; /* A temporary counter */
|
||||||
}
|
}
|
||||||
ptrNextNode = ptrStartNode;
|
ptrNextNode = ptrStartNode;
|
||||||
|
|
||||||
|
/*Checking ir szPath is a File with/wout extension*/
|
||||||
|
if (szPath[_tcslen(szPath) - 1] == _T('.'))
|
||||||
|
fPoint= TRUE;
|
||||||
|
|
||||||
/* Collect the results for the current folder */
|
/* Collect the results for the current folder */
|
||||||
hSearch = FindFirstFile(szFullPath, &wfdFileInfo);
|
hSearch = FindFirstFile(szFullPath, &wfdFileInfo);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (hSearch != INVALID_HANDLE_VALUE)
|
if (hSearch != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
/* Here we filter all the specified attributes */
|
/*If retrieved FileName has extension,and szPath doesnt have extension then JUMP the retrieved FileName*/
|
||||||
if ((wfdFileInfo.dwFileAttributes & lpFlags->stAttribs.dwAttribMask )
|
if(_tcschr(wfdFileInfo.cFileName,_T('.'))&&(fPoint==TRUE))
|
||||||
== (lpFlags->stAttribs.dwAttribMask & lpFlags->stAttribs.dwAttribVal ))
|
|
||||||
{
|
{
|
||||||
ptrNextNode->ptrNext = cmd_alloc(sizeof(DIRFINDLISTNODE));
|
continue;
|
||||||
if (ptrNextNode->ptrNext == NULL)
|
/* Here we filter all the specified attributes */
|
||||||
|
}else if ((wfdFileInfo.dwFileAttributes & lpFlags->stAttribs.dwAttribMask )
|
||||||
|
== (lpFlags->stAttribs.dwAttribMask & lpFlags->stAttribs.dwAttribVal ))
|
||||||
{
|
{
|
||||||
WARN("DEBUG: Cannot allocate memory for ptrNextNode->ptrNext!\n");
|
ptrNextNode->ptrNext = cmd_alloc(sizeof(DIRFINDLISTNODE));
|
||||||
while (ptrStartNode)
|
if (ptrNextNode->ptrNext == NULL)
|
||||||
{
|
{
|
||||||
ptrNextNode = ptrStartNode->ptrNext;
|
WARN("DEBUG: Cannot allocate memory for ptrNextNode->ptrNext!\n");
|
||||||
cmd_free(ptrStartNode);
|
while (ptrStartNode)
|
||||||
ptrStartNode = ptrNextNode;
|
{
|
||||||
dwCount --;
|
ptrNextNode = ptrStartNode->ptrNext;
|
||||||
|
cmd_free(ptrStartNode);
|
||||||
|
ptrStartNode = ptrNextNode;
|
||||||
|
dwCount --;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If cmd_alloc fails we go to next file in hope it works,
|
/* If cmd_alloc fails we go to next file in hope it works,
|
||||||
without braking the linked list! */
|
without braking the linked list! */
|
||||||
if (ptrNextNode->ptrNext)
|
if (ptrNextNode->ptrNext)
|
||||||
{
|
{
|
||||||
/* Copy the info of search at linked list */
|
/* Copy the info of search at linked list */
|
||||||
memcpy(&ptrNextNode->ptrNext->stFindInfo,
|
memcpy(&ptrNextNode->ptrNext->stFindInfo,
|
||||||
&wfdFileInfo,
|
&wfdFileInfo,
|
||||||
sizeof(WIN32_FIND_DATA));
|
sizeof(WIN32_FIND_DATA));
|
||||||
|
|
||||||
/* If lower case is selected do it here */
|
/* If lower case is selected do it here */
|
||||||
if (lpFlags->bLowerCase)
|
if (lpFlags->bLowerCase)
|
||||||
{
|
{
|
||||||
_tcslwr(ptrNextNode->ptrNext->stFindInfo.cAlternateFileName);
|
_tcslwr(ptrNextNode->ptrNext->stFindInfo.cAlternateFileName);
|
||||||
_tcslwr(ptrNextNode->ptrNext->stFindInfo.cFileName);
|
_tcslwr(ptrNextNode->ptrNext->stFindInfo.cFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Continue at next node at linked list */
|
/* Continue at next node at linked list */
|
||||||
ptrNextNode = ptrNextNode->ptrNext;
|
ptrNextNode = ptrNextNode->ptrNext;
|
||||||
dwCount ++;
|
dwCount ++;
|
||||||
|
|
||||||
/* Grab statistics */
|
/* Grab statistics */
|
||||||
if (wfdFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
if (wfdFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
{
|
{
|
||||||
/* Directory */
|
/* Directory */
|
||||||
dwCountDirs++;
|
dwCountDirs++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* File */
|
/* File */
|
||||||
dwCountFiles++;
|
dwCountFiles++;
|
||||||
u64Temp.HighPart = wfdFileInfo.nFileSizeHigh;
|
u64Temp.HighPart = wfdFileInfo.nFileSizeHigh;
|
||||||
u64Temp.LowPart = wfdFileInfo.nFileSizeLow;
|
u64Temp.LowPart = wfdFileInfo.nFileSizeLow;
|
||||||
u64CountBytes.QuadPart += u64Temp.QuadPart;
|
u64CountBytes.QuadPart += u64Temp.QuadPart;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} while(FindNextFile(hSearch, &wfdFileInfo));
|
} while(FindNextFile(hSearch, &wfdFileInfo));
|
||||||
FindClose(hSearch);
|
FindClose(hSearch);
|
||||||
|
|
Loading…
Reference in a new issue