Skip to content

Commit ed84cbe

Browse files
firewavewillenbr24
andcommitted
fixed #583 - fall back to GetFileInformationByHandle() when GetFileInformationByHandleEx() fails in simplecpp::FileDataCache::getFileId()
Co-authored-by: willenbr24 <willenbr24@users.noreply.github.com>
1 parent 5cd15b3 commit ed84cbe

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

simplecpp.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3126,7 +3126,21 @@ bool simplecpp::FileDataCache::getFileId(const std::string &path, FileID &id)
31263126
if (hFile == INVALID_HANDLE_VALUE)
31273127
return false;
31283128

3129-
const BOOL ret = GetFileInformationByHandleEx(hFile, FileIdInfo, &id.fileIdInfo, sizeof(id.fileIdInfo));
3129+
BOOL ret = GetFileInformationByHandleEx(hFile, FileIdInfo, &id.fileIdInfo, sizeof(id.fileIdInfo));
3130+
if (!ret) {
3131+
const DWORD err = GetLastError();
3132+
if (err == ERROR_INVALID_PARAMETER || // encountered when using a non-NTFS filesystem e.g. exFAT
3133+
err == ERROR_NOT_SUPPORTED) // encountered on Windows Server Core (used as a Docker container)
3134+
{
3135+
BY_HANDLE_FILE_INFORMATION fileInfo;
3136+
ret = GetFileInformationByHandle(hFile, &fileInfo);
3137+
if (ret) {
3138+
id.fileIdInfo.VolumeSerialNumber = static_cast<std::uint64_t>(fileInfo.dwVolumeSerialNumber);
3139+
id.fileIdInfo.FileId.IdentifierHi = static_cast<std::uint64_t>(fileInfo.nFileIndexHigh);
3140+
id.fileIdInfo.FileId.IdentifierLo = static_cast<std::uint64_t>(fileInfo.nFileIndexLow);
3141+
}
3142+
}
3143+
}
31303144

31313145
CloseHandle(hFile);
31323146

0 commit comments

Comments
 (0)