Support: Work around missing SetFileInformationByHandle on Wine

In r315079, fs::rename was reimplemented in terms of CreateFile and
SetFileInformationByHandle. Unfortunately, the latter isn't supported by
Wine. This adds a fallback to MoveFileEx for that case.

Differential Revision: https://reviews.llvm.org/D38817

llvm-svn: 315520
This commit is contained in:
Hans Wennborg 2017-10-11 22:04:14 +00:00
parent 6f1ae631f7
commit 17701ab5bd
1 changed files with 11 additions and 0 deletions

View File

@ -413,6 +413,17 @@ std::error_code rename(const Twine &From, const Twine &To) {
// a true error, so stop trying.
for (unsigned Retry = 0; Retry != 200; ++Retry) {
auto EC = rename_internal(FromHandle, To, true);
if (EC ==
std::error_code(ERROR_CALL_NOT_IMPLEMENTED, std::system_category())) {
// Wine doesn't support SetFileInformationByHandle in rename_internal.
// Fall back to MoveFileEx.
if (::MoveFileExW(WideFrom.begin(), WideTo.begin(),
MOVEFILE_REPLACE_EXISTING))
return std::error_code();
return mapWindowsError(GetLastError());
}
if (!EC || EC != errc::permission_denied)
return EC;