1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/*
* Copyright (C) 2023-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/compiler_interface/os_compiler_cache_helper.h"
#include "shared/source/helpers/path.h"
#include "shared/source/os_interface/windows/sys_calls.h"
#include "shared/source/utilities/debug_settings_reader.h"
#include <ShlObj.h>
#include <algorithm>
namespace NEO {
std::string getKnownFolderPath(REFKNOWNFOLDERID rfid) {
PWSTR path = nullptr;
auto result = SysCalls::shGetKnownFolderPath(rfid, 0, nullptr, &path);
if (result != S_OK) {
SysCalls::coTaskMemFree(path);
return std::string();
}
std::wstring temp(path);
SysCalls::coTaskMemFree(path);
std::string ret(temp.length(), 0);
std::transform(temp.begin(), temp.end(), ret.begin(), [](wchar_t c) {
return static_cast<char>(c);
});
return ret;
}
bool createCompilerCachePath(std::string &cacheDir) {
if (NEO::SysCalls::pathExists(cacheDir)) {
cacheDir = joinPath(cacheDir, "neo_compiler_cache");
if (NEO::SysCalls::pathExists(cacheDir)) {
return true;
}
auto result = SysCalls::createDirectoryA(cacheDir.c_str(), NULL);
if (result) {
return true;
}
if (SysCalls::getLastError() == ERROR_ALREADY_EXISTS) {
return true;
}
}
cacheDir = "";
return false;
}
bool checkDefaultCacheDirSettings(std::string &cacheDir, NEO::EnvironmentVariableReader &reader) {
cacheDir = getKnownFolderPath(FOLDERID_LocalAppData);
if (cacheDir.empty()) {
return false;
}
cacheDir = joinPath(cacheDir, "NEO\\");
if (!SysCalls::pathExists(cacheDir)) {
SysCalls::createDirectoryA(cacheDir.c_str(), NULL);
}
if (NEO::SysCalls::pathExists(cacheDir)) {
return createCompilerCachePath(cacheDir);
}
cacheDir = "";
return false;
}
time_t getFileModificationTime(const std::string &path) {
WIN32_FIND_DATAA ffd;
HANDLE hFind = INVALID_HANDLE_VALUE;
hFind = SysCalls::findFirstFileA(path.c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE) {
return 0;
}
ULARGE_INTEGER uli;
uli.LowPart = ffd.ftLastWriteTime.dwLowDateTime;
uli.HighPart = ffd.ftLastWriteTime.dwHighDateTime;
SysCalls::findClose(hFind);
return uli.QuadPart;
}
size_t getFileSize(const std::string &path) {
WIN32_FIND_DATAA ffd;
HANDLE hFind = INVALID_HANDLE_VALUE;
hFind = SysCalls::findFirstFileA(path.c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE) {
return 0u;
}
SysCalls::findClose(hFind);
return static_cast<size_t>((ffd.nFileSizeHigh * (MAXDWORD + 1)) + ffd.nFileSizeLow);
}
} // namespace NEO
|