Skip to content

getFileId() error in windows docker container #583

@willenbr24

Description

@willenbr24

We are using cppcheck in a Windows Docker container (windowsservercore-20H2) and have noticed that the function simplecpp::FileDataCache::getFileId() does not work.

This is because the Windows API function GetFileInformationByHandleEx is not available in the Docker container (Error 50: ERROR_NOT_SUPPORTED). We also tested this on windowsservercore-ltsc2025, but the problem persists there as well.
Because of this problem, cppcheck cannot find files and therefore does not work.

However, it works when using the simpler API function GetFileInformationByHandle (without Ex).
Here is my fix for the problem:

#ifdef DOCKER
// New implementation
    BY_HANDLE_FILE_INFORMATION fileInfo;
    const BOOL ret = GetFileInformationByHandle(hFile, &fileInfo);
    if (ret) {
        id.fileIdInfo.VolumeSerialNumber = static_cast<std::uint64_t>(fileInfo.dwVolumeSerialNumber);
        id.fileIdInfo.FileId.IdentifierHi = static_cast<std::uint64_t>(fileInfo.nFileIndexHigh);
        id.fileIdInfo.FileId.IdentifierLo = static_cast<std::uint64_t>(fileInfo.nFileIndexLow);
    }
#else
// Old implementation
    const BOOL ret = GetFileInformationByHandleEx(hFile, FileIdInfo, &id.fileIdInfo, sizeof(id.fileIdInfo));
#endif

The problem can also be reproduced using testrunner.exe.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions