mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 10:47:59 +08:00
cmSystemTools: Define directory-specific Windows filesystem retry settings
Inspired-by: Ron W Moore <webbtrail@gmail.com>
This commit is contained in:
@@ -749,33 +749,78 @@ std::string cmSystemTools::FileExistsInParentDirectories(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct WindowsFileRetryInit
|
||||||
|
{
|
||||||
|
cmSystemTools::WindowsFileRetry Retry;
|
||||||
|
bool Explicit;
|
||||||
|
};
|
||||||
|
|
||||||
|
WindowsFileRetryInit InitWindowsFileRetry(wchar_t const* const values[2],
|
||||||
|
unsigned int const defaults[2])
|
||||||
|
{
|
||||||
|
unsigned int data[2] = { 0, 0 };
|
||||||
|
HKEY const keys[2] = { HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE };
|
||||||
|
for (int k = 0; k < 2; ++k) {
|
||||||
|
HKEY hKey;
|
||||||
|
if (RegOpenKeyExW(keys[k], L"Software\\Kitware\\CMake\\Config", 0,
|
||||||
|
KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
|
||||||
|
for (int v = 0; v < 2; ++v) {
|
||||||
|
DWORD dwData, dwType, dwSize = 4;
|
||||||
|
if (!data[v] &&
|
||||||
|
RegQueryValueExW(hKey, values[v], 0, &dwType, (BYTE*)&dwData,
|
||||||
|
&dwSize) == ERROR_SUCCESS &&
|
||||||
|
dwType == REG_DWORD && dwSize == 4) {
|
||||||
|
data[v] = static_cast<unsigned int>(dwData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WindowsFileRetryInit init;
|
||||||
|
init.Explicit = data[0] || data[1];
|
||||||
|
init.Retry.Count = data[0] ? data[0] : defaults[0];
|
||||||
|
init.Retry.Delay = data[1] ? data[1] : defaults[1];
|
||||||
|
return init;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowsFileRetryInit InitWindowsFileRetry()
|
||||||
|
{
|
||||||
|
static wchar_t const* const values[2] = { L"FilesystemRetryCount",
|
||||||
|
L"FilesystemRetryDelay" };
|
||||||
|
static unsigned int const defaults[2] = { 5, 500 };
|
||||||
|
return InitWindowsFileRetry(values, defaults);
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowsFileRetryInit InitWindowsDirectoryRetry()
|
||||||
|
{
|
||||||
|
static wchar_t const* const values[2] = { L"FilesystemDirectoryRetryCount",
|
||||||
|
L"FilesystemDirectoryRetryDelay" };
|
||||||
|
static unsigned int const defaults[2] = { 120, 500 };
|
||||||
|
WindowsFileRetryInit dirInit = InitWindowsFileRetry(values, defaults);
|
||||||
|
if (dirInit.Explicit) {
|
||||||
|
return dirInit;
|
||||||
|
}
|
||||||
|
WindowsFileRetryInit fileInit = InitWindowsFileRetry();
|
||||||
|
if (fileInit.Explicit) {
|
||||||
|
return fileInit;
|
||||||
|
}
|
||||||
|
return dirInit;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end of anonymous namespace
|
||||||
|
|
||||||
cmSystemTools::WindowsFileRetry cmSystemTools::GetWindowsFileRetry()
|
cmSystemTools::WindowsFileRetry cmSystemTools::GetWindowsFileRetry()
|
||||||
{
|
{
|
||||||
static WindowsFileRetry retry = { 0, 0 };
|
static WindowsFileRetry retry = InitWindowsFileRetry().Retry;
|
||||||
if (!retry.Count) {
|
return retry;
|
||||||
unsigned int data[2] = { 0, 0 };
|
}
|
||||||
HKEY const keys[2] = { HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE };
|
|
||||||
wchar_t const* const values[2] = { L"FilesystemRetryCount",
|
cmSystemTools::WindowsFileRetry cmSystemTools::GetWindowsDirectoryRetry()
|
||||||
L"FilesystemRetryDelay" };
|
{
|
||||||
for (int k = 0; k < 2; ++k) {
|
static cmSystemTools::WindowsFileRetry retry =
|
||||||
HKEY hKey;
|
InitWindowsDirectoryRetry().Retry;
|
||||||
if (RegOpenKeyExW(keys[k], L"Software\\Kitware\\CMake\\Config", 0,
|
|
||||||
KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
|
|
||||||
for (int v = 0; v < 2; ++v) {
|
|
||||||
DWORD dwData, dwType, dwSize = 4;
|
|
||||||
if (!data[v] &&
|
|
||||||
RegQueryValueExW(hKey, values[v], 0, &dwType, (BYTE*)&dwData,
|
|
||||||
&dwSize) == ERROR_SUCCESS &&
|
|
||||||
dwType == REG_DWORD && dwSize == 4) {
|
|
||||||
data[v] = static_cast<unsigned int>(dwData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
retry.Count = data[0] ? data[0] : 5;
|
|
||||||
retry.Delay = data[1] ? data[1] : 500;
|
|
||||||
}
|
|
||||||
return retry;
|
return retry;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -434,6 +434,7 @@ public:
|
|||||||
unsigned int Delay;
|
unsigned int Delay;
|
||||||
};
|
};
|
||||||
static WindowsFileRetry GetWindowsFileRetry();
|
static WindowsFileRetry GetWindowsFileRetry();
|
||||||
|
static WindowsFileRetry GetWindowsDirectoryRetry();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Get the real path for a given path, removing all symlinks.
|
/** Get the real path for a given path, removing all symlinks.
|
||||||
|
Reference in New Issue
Block a user