diff options
-rw-r--r-- | llvm/lib/Support/Windows/Path.inc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc index 365ab01c0a16..a4ffc0ec4313 100644 --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/lib/Support/Windows/Path.inc @@ -402,6 +402,20 @@ std::error_code is_local(int FD, bool &Result) { } 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<wchar_t, 128> 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; + + if (!IsLocal) + return std::error_code(); + + // The file is on a local drive, set the DeleteFile to true. FILE_DISPOSITION_INFO Disposition; Disposition.DeleteFile = Delete; if (!SetFileInformationByHandle(Handle, FileDispositionInfo, &Disposition, |