diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/lib/Support/Windows/Path.inc @@ -402,18 +402,23 @@ } static std::error_code setDeleteDisposition(HANDLE Handle, bool Delete) { - // First, check if the file is on a network (non-local) drive. If so, don't - // set DeleteFile to true, since it prevents opening the file for writes. - SmallVector FinalPath; - if (std::error_code EC = realPathFromHandle(Handle, FinalPath)) - return EC; + // First check if the file is on network (non-local) drive; don't ask for + // deletion in that case, since it prevents opening the file for writes. + // When Delete is false skip the check, since on Windows 7 the function + // realPathFromHandle() below would fail. In that case, network files would + // also get the 'false' flag, but that is fine. + if (Delete) { + SmallVector FinalPath; + if (std::error_code EC = realPathFromHandle(Handle, FinalPath)) + return EC; - bool IsLocal; - if (std::error_code EC = is_local_internal(FinalPath, IsLocal)) - return EC; + bool IsLocal; + if (std::error_code EC = is_local_internal(FinalPath, IsLocal)) + return EC; - if (!IsLocal) - return std::error_code(); + if (!IsLocal) + return std::error_code(); + } // The file is on a local drive, set the DeleteFile to true. FILE_DISPOSITION_INFO Disposition;