Skip to content

Commit cf62b1d

Browse files
committed
[Support] PR42623: Avoid setting the delete-on-close bit if a TempFile doesn't reside on a local drive
On Windows, after commit 61e6b9e, 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
1 parent 4df0842 commit cf62b1d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

llvm/lib/Support/Windows/Path.inc

+14
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,20 @@ std::error_code is_local(int FD, bool &Result) {
402402
}
403403

404404
static std::error_code setDeleteDisposition(HANDLE Handle, bool Delete) {
405+
// First, check if the file is on a network (non-local) drive. If so, don't
406+
// set DeleteFile to true, since it prevents opening the file for writes.
407+
SmallVector<wchar_t, 128> FinalPath;
408+
if (std::error_code EC = realPathFromHandle(Handle, FinalPath))
409+
return EC;
410+
411+
bool IsLocal;
412+
if (std::error_code EC = is_local_internal(FinalPath, IsLocal))
413+
return EC;
414+
415+
if (!IsLocal)
416+
return std::error_code();
417+
418+
// The file is on a local drive, set the DeleteFile to true.
405419
FILE_DISPOSITION_INFO Disposition;
406420
Disposition.DeleteFile = Delete;
407421
if (!SetFileInformationByHandle(Handle, FileDispositionInfo, &Disposition,

0 commit comments

Comments
 (0)