@@ -88,10 +88,9 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
88
88
AddBuffer (std::move(AddBuffer)), TempFile(std::move(TempFile)),
89
89
ModuleName(ModuleName), Task(Task) {}
90
90
91
- Error commit () override {
92
- Error E = CachedFileStream::commit ();
93
- if (E)
94
- return E;
91
+ ~CacheStream () {
92
+ // TODO: Manually commit rather than using non-trivial destructor,
93
+ // allowing to replace report_fatal_errors with a return Error.
95
94
96
95
// Make sure the stream is closed before committing it.
97
96
OS.reset ();
@@ -101,12 +100,10 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
101
100
MemoryBuffer::getOpenFile (
102
101
sys::fs::convertFDToNativeFile (TempFile.FD ), ObjectPathName,
103
102
/* FileSize=*/ -1 , /* RequiresNullTerminator=*/ false );
104
- if (!MBOrErr) {
105
- std::error_code EC = MBOrErr.getError ();
106
- return createStringError (EC, Twine (" Failed to open new cache file " ) +
107
- TempFile.TmpName + " : " +
108
- EC.message () + " \n " );
109
- }
103
+ if (!MBOrErr)
104
+ report_fatal_error (Twine (" Failed to open new cache file " ) +
105
+ TempFile.TmpName + " : " +
106
+ MBOrErr.getError ().message () + " \n " );
110
107
111
108
// On POSIX systems, this will atomically replace the destination if
112
109
// it already exists. We try to emulate this on Windows, but this may
@@ -117,14 +114,11 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
117
114
// AddBuffer a copy of the bytes we wrote in that case. We do this
118
115
// instead of just using the existing file, because the pruner might
119
116
// delete the file before we get a chance to use it.
120
- E = TempFile.keep (ObjectPathName);
117
+ Error E = TempFile.keep (ObjectPathName);
121
118
E = handleErrors (std::move (E), [&](const ECError &E) -> Error {
122
119
std::error_code EC = E.convertToErrorCode ();
123
120
if (EC != errc::permission_denied)
124
- return createStringError (
125
- EC, Twine (" Failed to rename temporary file " ) +
126
- TempFile.TmpName + " to " + ObjectPathName + " : " +
127
- EC.message () + " \n " );
121
+ return errorCodeToError (EC);
128
122
129
123
auto MBCopy = MemoryBuffer::getMemBufferCopy ((*MBOrErr)->getBuffer (),
130
124
ObjectPathName);
@@ -137,10 +131,11 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
137
131
});
138
132
139
133
if (E)
140
- return E;
134
+ report_fatal_error (Twine (" Failed to rename temporary file " ) +
135
+ TempFile.TmpName + " to " + ObjectPathName + " : " +
136
+ toString (std::move (E)) + " \n " );
141
137
142
138
AddBuffer (Task, ModuleName, std::move (*MBOrErr));
143
- return Error::success ();
144
139
}
145
140
};
146
141
0 commit comments