[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,18 +546,17 @@ 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))
@ -565,17 +564,30 @@ demFileFindFirst(OUT PVOID lpFindFileData,
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();
}
/* Fill the block */
FindFileBlock->DriveLetter = CurrentDrive + 'A';
FindFileBlock->AttribMask = AttribMask;
FindFileBlock->SearchHandle = SearchHandle;
FindFileBlock->Attributes = LOBYTE(FindData.dwFileAttributes); 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,8 +601,19 @@ demFileFindNext(OUT PVOID lpFindFileData)
do do
{ {
/* Continue searching as long as we haven't found a matching file */
/* If we failed at some point, close the search and return an error */
if (!FindNextFileA(FindFileBlock->SearchHandle, &FindData)) if (!FindNextFileA(FindFileBlock->SearchHandle, &FindData))
{
FindClose(FindFileBlock->SearchHandle);
return GetLastError(); return GetLastError();
}
}
while ((FindData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN |
FILE_ATTRIBUTE_SYSTEM |
FILE_ATTRIBUTE_DIRECTORY))
& ~FindFileBlock->AttribMask);
/* Update the block */ /* Update the block */
FindFileBlock->Attributes = LOBYTE(FindData.dwFileAttributes); FindFileBlock->Attributes = LOBYTE(FindData.dwFileAttributes);
@ -599,12 +622,11 @@ demFileFindNext(OUT PVOID lpFindFileData)
&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)
while((FindData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | strncpy(FindFileBlock->FileName, FindData.cAlternateFileName, sizeof(FindFileBlock->FileName));
FILE_ATTRIBUTE_SYSTEM | else
FILE_ATTRIBUTE_DIRECTORY)) GetShortPathNameA(FindData.cFileName, FindFileBlock->FileName, sizeof(FindFileBlock->FileName));
& ~FindFileBlock->AttribMask);
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }