summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonald Wampler <rdwampler@gmail.com>2020-09-28 17:07:44 -0400
committerTom Stellard <tstellar@redhat.com>2020-12-15 18:23:10 -0500
commit6ec777c2f6496b4fe1d78cc6d6871a3dc931a185 (patch)
tree5f3bf215cc384e813e9d16d6381062e22be0cb5f
parentf684355e0292b8e24a0870ecfda126fb15c9eb93 (diff)
downloadllvm-6ec777c2f6496b4fe1d78cc6d6871a3dc931a185.tar.gz
[Support] PR42623: Avoid setting the delete-on-close bit if a TempFile doesn't reside on a local drive
On Windows, after commit 881ba104656c40098d4bc90c52613c08136f0fe1, tools using TempFile would error with "bad file descriptor" when writing the file on a network drive. It appears that setting the delete-on-close bit via SetFileInformationByHandle/FileDispositionInfo prevented it from accessing the file on network drives, and although using FILE_DISPOSITION_INFO seems to work, it causes other troubles. Differential Revision: https://reviews.llvm.org/D81803 (cherry picked from commit 79657e2339b58bc01fe1b85a448bb073d57d90bb)
-rw-r--r--llvm/lib/Support/Windows/Path.inc14
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,