Index: llvm/lib/Support/Path.cpp =================================================================== --- llvm/lib/Support/Path.cpp +++ llvm/lib/Support/Path.cpp @@ -1178,11 +1178,6 @@ } FD = -1; -#ifdef _WIN32 - // On windows closing will remove the file. - TmpName = ""; - return Error::success(); -#else // Always try to close and remove. std::error_code RemoveEC; if (!TmpName.empty()) { @@ -1192,31 +1187,12 @@ TmpName = ""; } return errorCodeToError(RemoveEC); -#endif } Error TempFile::keep(const Twine &Name) { assert(!Done); Done = true; // Always try to close and rename. -#ifdef _WIN32 - // If we can't cancel the delete don't rename. - auto H = reinterpret_cast(_get_osfhandle(FD)); - std::error_code RenameEC = setDeleteDisposition(H, false); - if (!RenameEC) { - RenameEC = rename_fd(FD, Name); - // If rename failed because it's cross-device, copy instead - if (RenameEC == - std::error_code(ERROR_NOT_SAME_DEVICE, std::system_category())) { - RenameEC = copy_file(TmpName, Name); - setDeleteDisposition(H, true); - } - } - - // If we can't rename, discard the temporary file. - if (RenameEC) - setDeleteDisposition(H, true); -#else std::error_code RenameEC = fs::rename(TmpName, Name); if (RenameEC) { // If we can't rename, try to copy to work around cross-device link issues. @@ -1226,7 +1202,6 @@ remove(TmpName); } sys::DontRemoveFileOnSignal(TmpName); -#endif if (!RenameEC) TmpName = ""; @@ -1244,13 +1219,7 @@ assert(!Done); Done = true; -#ifdef _WIN32 - auto H = reinterpret_cast(_get_osfhandle(FD)); - if (std::error_code EC = setDeleteDisposition(H, false)) - return errorCodeToError(EC); -#else sys::DontRemoveFileOnSignal(TmpName); -#endif TmpName = ""; Index: llvm/lib/Support/Windows/Path.inc =================================================================== --- llvm/lib/Support/Windows/Path.inc +++ llvm/lib/Support/Windows/Path.inc @@ -250,7 +250,7 @@ return ec; if (std::error_code ec = widenPath(to, wide_to)) return ec; - + if (!::CreateHardLinkW(wide_from.begin(), wide_to.begin(), NULL)) return mapWindowsError(::GetLastError()); @@ -402,15 +402,6 @@ return is_local_internal(FinalPath, Result); } -static std::error_code setDeleteDisposition(HANDLE Handle, bool Delete) { - FILE_DISPOSITION_INFO Disposition; - Disposition.DeleteFile = Delete; - if (!SetFileInformationByHandle(Handle, FileDispositionInfo, &Disposition, - sizeof(Disposition))) - return mapWindowsError(::GetLastError()); - return std::error_code(); -} - static std::error_code rename_internal(HANDLE FromHandle, const Twine &To, bool ReplaceIfExists) { SmallVector ToWide; @@ -1166,12 +1157,6 @@ } } - if (Flags & OF_Delete) { - if ((EC = setDeleteDisposition(Result, true))) { - ::CloseHandle(Result); - return errorCodeToError(EC); - } - } return Result; }