[NTVDM]: Fix DOS file find. Introduced in r61507, it was indeed untested...

svn path=/trunk/; revision=67619
This commit is contained in:
Hermès Bélusca-Maïto 2015-05-10 12:25:27 +00:00
parent 122a0a5ccc
commit 86ba2faa4e

View file

@ -546,36 +546,48 @@ demFileFindFirst(OUT PVOID lpFindFileData,
{ {
BOOLEAN Success = TRUE; BOOLEAN Success = TRUE;
WIN32_FIND_DATAA FindData; WIN32_FIND_DATAA FindData;
HANDLE SearchHandle;
PDOS_FIND_FILE_BLOCK FindFileBlock = (PDOS_FIND_FILE_BLOCK)lpFindFileData; PDOS_FIND_FILE_BLOCK FindFileBlock = (PDOS_FIND_FILE_BLOCK)lpFindFileData;
/* Fill the block */ /* Start a search */
FindFileBlock->DriveLetter = CurrentDrive + 'A'; SearchHandle = FindFirstFileA(FileName, &FindData);
FindFileBlock->AttribMask = AttribMask; if (SearchHandle == INVALID_HANDLE_VALUE) return GetLastError();
FindFileBlock->SearchHandle = FindFirstFileA(FileName, &FindData);
if (FindFileBlock->SearchHandle == INVALID_HANDLE_VALUE) return GetLastError();
do do
{ {
/* Check the attributes */ /* Check the attributes and retry as long as we haven't found a matching file */
if (!((FindData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | if (((FindData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN |
FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_SYSTEM |
FILE_ATTRIBUTE_DIRECTORY)) FILE_ATTRIBUTE_DIRECTORY))
& ~AttribMask)) & ~AttribMask))
{ {
break; break;
} }
} }
while ((Success = FindNextFileA(FindFileBlock->SearchHandle, &FindData))); while ((Success = FindNextFileA(SearchHandle, &FindData)));
if (!Success) return GetLastError(); /* If we failed at some point, close the search and return an error */
if (!Success)
{
FindClose(SearchHandle);
return GetLastError();
}
FindFileBlock->Attributes = LOBYTE(FindData.dwFileAttributes); /* Fill the block */
FindFileBlock->DriveLetter = CurrentDrive + 'A';
FindFileBlock->AttribMask = AttribMask;
FindFileBlock->SearchHandle = SearchHandle;
FindFileBlock->Attributes = LOBYTE(FindData.dwFileAttributes);
FileTimeToDosDateTime(&FindData.ftLastWriteTime, FileTimeToDosDateTime(&FindData.ftLastWriteTime,
&FindFileBlock->FileDate, &FindFileBlock->FileDate,
&FindFileBlock->FileTime); &FindFileBlock->FileTime);
FindFileBlock->FileSize = FindData.nFileSizeHigh ? 0xFFFFFFFF FindFileBlock->FileSize = FindData.nFileSizeHigh ? 0xFFFFFFFF
: FindData.nFileSizeLow; : FindData.nFileSizeLow;
strcpy(FindFileBlock->FileName, FindData.cAlternateFileName); /* Build a short path name */
if (*FindData.cAlternateFileName)
strncpy(FindFileBlock->FileName, FindData.cAlternateFileName, sizeof(FindFileBlock->FileName));
else
GetShortPathNameA(FindData.cFileName, FindFileBlock->FileName, sizeof(FindFileBlock->FileName));
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
@ -589,22 +601,32 @@ demFileFindNext(OUT PVOID lpFindFileData)
do do
{ {
if (!FindNextFileA(FindFileBlock->SearchHandle, &FindData)) /* Continue searching as long as we haven't found a matching file */
return GetLastError();
/* Update the block */ /* If we failed at some point, close the search and return an error */
FindFileBlock->Attributes = LOBYTE(FindData.dwFileAttributes); if (!FindNextFileA(FindFileBlock->SearchHandle, &FindData))
FileTimeToDosDateTime(&FindData.ftLastWriteTime, {
&FindFileBlock->FileDate, FindClose(FindFileBlock->SearchHandle);
&FindFileBlock->FileTime); return GetLastError();
FindFileBlock->FileSize = FindData.nFileSizeHigh ? 0xFFFFFFFF }
: FindData.nFileSizeLow;
strcpy(FindFileBlock->FileName, FindData.cAlternateFileName);
} }
while((FindData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | while ((FindData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN |
FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_SYSTEM |
FILE_ATTRIBUTE_DIRECTORY)) FILE_ATTRIBUTE_DIRECTORY))
& ~FindFileBlock->AttribMask); & ~FindFileBlock->AttribMask);
/* Update the block */
FindFileBlock->Attributes = LOBYTE(FindData.dwFileAttributes);
FileTimeToDosDateTime(&FindData.ftLastWriteTime,
&FindFileBlock->FileDate,
&FindFileBlock->FileTime);
FindFileBlock->FileSize = FindData.nFileSizeHigh ? 0xFFFFFFFF
: FindData.nFileSizeLow;
/* Build a short path name */
if (*FindData.cAlternateFileName)
strncpy(FindFileBlock->FileName, FindData.cAlternateFileName, sizeof(FindFileBlock->FileName));
else
GetShortPathNameA(FindData.cFileName, FindFileBlock->FileName, sizeof(FindFileBlock->FileName));
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }