forked from Eelis/geordi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllvm-no-temp-files.patch
146 lines (132 loc) · 4.85 KB
/
llvm-no-temp-files.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
Index: lib/Support/FileOutputBuffer.cpp
===================================================================
--- lib/Support/FileOutputBuffer.cpp (revision 246397)
+++ lib/Support/FileOutputBuffer.cpp (working copy)
@@ -31,7 +31,6 @@
: Region(std::move(R)), FinalPath(Path), TempPath(TmpPath) {}
FileOutputBuffer::~FileOutputBuffer() {
- sys::fs::remove(Twine(TempPath));
}
ErrorOr<std::unique_ptr<FileOutputBuffer>>
@@ -56,11 +55,6 @@
return make_error_code(errc::operation_not_permitted);
}
- // Delete target file.
- EC = sys::fs::remove(FilePath);
- if (EC)
- return EC;
-
unsigned Mode = sys::fs::all_read | sys::fs::all_write;
// If requested, make the output file executable.
if (Flags & F_executable)
@@ -69,8 +63,7 @@
// Create new file in same directory but with random name.
SmallString<128> TempFilePath;
int FD;
- EC = sys::fs::createUniqueFile(Twine(FilePath) + ".tmp%%%%%%%", FD,
- TempFilePath, Mode);
+ EC = sys::fs::openFileForWrite(FilePath, FD, sys::fs::F_None);
if (EC)
return EC;
@@ -105,10 +98,6 @@ std::error_code FileOutputBuffer::commit() {
// Unmap buffer, letting OS flush dirty pages to file on disk.
Region.reset();
-
- // Rename file to final name.
- std::error_code EC = sys::fs::rename(Twine(TempPath), Twine(FinalPath));
- sys::DontRemoveFileOnSignal(TempPath);
- return EC;
+ return std::error_code();
}
} // namespace
Index: tools/clang/lib/Frontend/ASTUnit.cpp
===================================================================
--- tools/clang/lib/Frontend/ASTUnit.cpp (revision 244347)
+++ tools/clang/lib/Frontend/ASTUnit.cpp (working copy)
@@ -2455,11 +2455,8 @@
// Write to a temporary file and later rename it to the actual file, to avoid
// possible race conditions.
- SmallString<128> TempPath;
- TempPath = File;
- TempPath += "-%%%%%%%%";
int fd;
- if (llvm::sys::fs::createUniqueFile(TempPath, fd, TempPath))
+ if (llvm::sys::fs::openFileForWrite(File, fd, llvm::sys::fs::F_None))
return true;
// FIXME: Can we somehow regenerate the stat cache here, or do we need to
@@ -2473,11 +2470,6 @@
return true;
}
- if (llvm::sys::fs::rename(TempPath, File)) {
- llvm::sys::fs::remove(TempPath);
- return true;
- }
-
return false;
}
Index: tools/clang/lib/Frontend/CompilerInstance.cpp
===================================================================
--- tools/clang/lib/Frontend/CompilerInstance.cpp (revision 244347)
+++ tools/clang/lib/Frontend/CompilerInstance.cpp (working copy)
@@ -606,6 +606,8 @@
assert((!CreateMissingDirectories || UseTemporary) &&
"CreateMissingDirectories is only allowed when using temporary files");
+ UseTemporary = false;
+
std::string OutFile, TempFile;
if (!OutputPath.empty()) {
OutFile = OutputPath;
Index: tools/clang/lib/Rewrite/Rewriter.cpp
===================================================================
--- tools/clang/lib/Rewrite/Rewriter.cpp (revision 244347)
+++ tools/clang/lib/Rewrite/Rewriter.cpp (working copy)
@@ -403,41 +403,20 @@
public:
AtomicallyMovedFile(DiagnosticsEngine &Diagnostics, StringRef Filename,
bool &AllWritten)
- : Diagnostics(Diagnostics), Filename(Filename), AllWritten(AllWritten) {
- TempFilename = Filename;
- TempFilename += "-%%%%%%%%";
+ : Diagnostics(Diagnostics), AllWritten(AllWritten) {
int FD;
- if (llvm::sys::fs::createUniqueFile(TempFilename, FD, TempFilename)) {
+ if (llvm::sys::fs::openFileForWrite(Filename, FD, llvm::sys::fs::F_None)) {
AllWritten = false;
- Diagnostics.Report(clang::diag::err_unable_to_make_temp)
- << TempFilename;
} else {
FileStream.reset(new llvm::raw_fd_ostream(FD, /*shouldClose=*/true));
}
}
- ~AtomicallyMovedFile() {
- if (!ok()) return;
-
- // Close (will also flush) theFileStream.
- FileStream->close();
- if (std::error_code ec = llvm::sys::fs::rename(TempFilename, Filename)) {
- AllWritten = false;
- Diagnostics.Report(clang::diag::err_unable_to_rename_temp)
- << TempFilename << Filename << ec.message();
- // If the remove fails, there's not a lot we can do - this is already an
- // error.
- llvm::sys::fs::remove(TempFilename);
- }
- }
-
bool ok() { return (bool)FileStream; }
raw_ostream &getStream() { return *FileStream; }
private:
DiagnosticsEngine &Diagnostics;
- StringRef Filename;
- SmallString<128> TempFilename;
std::unique_ptr<llvm::raw_fd_ostream> FileStream;
bool &AllWritten;
};
Index: lib/Support/Unix/Signals.inc
===================================================================
--- lib/Support/Unix/Signals.inc (revision 246397)
+++ lib/Support/Unix/Signals.inc (working copy)
@@ -90,6 +90,7 @@
static void RegisterHandler(int Signal) {
+ return;
assert(NumRegisteredSignals < array_lengthof(RegisteredSignalInfo) &&