summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Path.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2017-11-28 01:41:22 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2017-11-28 01:41:22 +0000
commit3ecd20430cace7eb9e78ef0a9ff9cc95a377feb9 (patch)
tree41f34ae2d71b08ead8f0a899fe24f0f6aebc2546 /llvm/lib/Support/Path.cpp
parentddbc340c20495d9add6b2eeab3871a9f8baa098b (diff)
downloadbcm5719-llvm-3ecd20430cace7eb9e78ef0a9ff9cc95a377feb9.tar.gz
bcm5719-llvm-3ecd20430cace7eb9e78ef0a9ff9cc95a377feb9.zip
Use FILE_FLAG_DELETE_ON_CLOSE for TempFile on windows.
We won't see the temp file no more. llvm-svn: 319137
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r--llvm/lib/Support/Path.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index c824d836969..d4b9d02e030 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -1068,12 +1068,15 @@ TempFile::~TempFile() { assert(Done); }
Error TempFile::discard() {
Done = true;
- // Always try to close and remove.
std::error_code RemoveEC;
+// On windows closing will remove the file.
+#ifndef LLVM_ON_WIN32
+ // Always try to close and remove.
if (!TmpName.empty()) {
RemoveEC = fs::remove(TmpName);
sys::DontRemoveFileOnSignal(TmpName);
}
+#endif
if (!RemoveEC)
TmpName = "";
@@ -1091,8 +1094,15 @@ Error TempFile::keep(const Twine &Name) {
assert(!Done);
Done = true;
// Always try to close and rename.
+#ifdef LLVM_ON_WIN32
+ // If we cant't cancel the delete don't rename.
+ std::error_code RenameEC = cancelDeleteOnClose(FD);
+ if (!RenameEC)
+ RenameEC = rename_fd(FD, Name);
+#else
std::error_code RenameEC = fs::rename(TmpName, Name);
sys::DontRemoveFileOnSignal(TmpName);
+#endif
if (!RenameEC)
TmpName = "";
@@ -1110,7 +1120,13 @@ Error TempFile::keep() {
assert(!Done);
Done = true;
+#ifdef LLVM_ON_WIN32
+ if (std::error_code EC = cancelDeleteOnClose(FD))
+ return errorCodeToError(EC);
+#else
sys::DontRemoveFileOnSignal(TmpName);
+#endif
+
TmpName = "";
if (close(FD) == -1) {
@@ -1125,16 +1141,19 @@ Error TempFile::keep() {
Expected<TempFile> TempFile::create(const Twine &Model, unsigned Mode) {
int FD;
SmallString<128> ResultPath;
- if (std::error_code EC = createUniqueFile(Model, FD, ResultPath, Mode))
+ if (std::error_code EC = createUniqueFile(Model, FD, ResultPath, Mode,
+ sys::fs::F_RW | sys::fs::F_Delete))
return errorCodeToError(EC);
- // Make sure we delete the file when RemoveFileOnSignal fails.
TempFile Ret(ResultPath, FD);
+#ifndef LLVM_ON_WIN32
if (sys::RemoveFileOnSignal(ResultPath)) {
+ // Make sure we delete the file when RemoveFileOnSignal fails.
consumeError(Ret.discard());
std::error_code EC(errc::operation_not_permitted);
return errorCodeToError(EC);
}
+#endif
return std::move(Ret);
}
}
OpenPOWER on IntegriCloud