Index: lib/Support/Windows/Path.inc =================================================================== --- lib/Support/Windows/Path.inc +++ lib/Support/Windows/Path.inc @@ -384,6 +384,19 @@ return std::error_code(); } +static bool is_wine() { + static bool Initialized = false; + static bool IsWine = false; + + if (!Initialized) { + if (HMODULE ntdll = ::GetModuleHandleA("ntdll.dll")) + IsWine = ::GetProcAddress(ntdll, "wine_get_version"); + Initialized = true; + } + + return IsWine; +} + std::error_code rename(const Twine &From, const Twine &To) { // Convert to utf-16. SmallVector WideFrom; @@ -393,6 +406,13 @@ if (std::error_code EC = widenPath(To, WideTo)) return EC; + if (is_wine()) { + // Wine doesn't support SetFileInformationByHandle used below. + if (::MoveFileExW(WideFrom.begin(), WideTo.begin(), MOVEFILE_REPLACE_EXISTING)) + return std::error_code(); + return mapWindowsError(GetLastError()); + } + ScopedFileHandle FromHandle; // Retry this a few times to defeat badly behaved file system scanners. for (unsigned Retry = 0; Retry != 200; ++Retry) {