-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Modify the localCache API to require an explicit commit on CachedFile… #115331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
3fdba46
7782900
8f99856
861e889
46b18d8
2d38a85
987f307
c8ed684
d4cd9ea
46660c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,7 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef, | |
| sys::fs::TempFile TempFile; | ||
| std::string ModuleName; | ||
| unsigned Task; | ||
| bool Committed = false; | ||
|
|
||
| CacheStream(std::unique_ptr<raw_pwrite_stream> OS, AddBufferFn AddBuffer, | ||
| sys::fs::TempFile TempFile, std::string EntryPath, | ||
|
|
@@ -88,9 +89,10 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef, | |
| AddBuffer(std::move(AddBuffer)), TempFile(std::move(TempFile)), | ||
| ModuleName(ModuleName), Task(Task) {} | ||
|
|
||
| ~CacheStream() { | ||
| // TODO: Manually commit rather than using non-trivial destructor, | ||
| // allowing to replace report_fatal_errors with a return Error. | ||
| Error commit() override { | ||
| if (Committed) | ||
| return Error::success(); | ||
|
||
| Committed = true; | ||
|
|
||
| // Make sure the stream is closed before committing it. | ||
| OS.reset(); | ||
|
|
@@ -100,10 +102,12 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef, | |
| MemoryBuffer::getOpenFile( | ||
| sys::fs::convertFDToNativeFile(TempFile.FD), ObjectPathName, | ||
| /*FileSize=*/-1, /*RequiresNullTerminator=*/false); | ||
| if (!MBOrErr) | ||
| report_fatal_error(Twine("Failed to open new cache file ") + | ||
| TempFile.TmpName + ": " + | ||
| MBOrErr.getError().message() + "\n"); | ||
| if (!MBOrErr) { | ||
| std::error_code EC = MBOrErr.getError(); | ||
| return createStringError(EC, Twine("Failed to open new cache file ") + | ||
| TempFile.TmpName + ": " + | ||
| EC.message() + "\n"); | ||
| } | ||
|
|
||
| // On POSIX systems, this will atomically replace the destination if | ||
| // it already exists. We try to emulate this on Windows, but this may | ||
|
|
@@ -118,7 +122,10 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef, | |
| E = handleErrors(std::move(E), [&](const ECError &E) -> Error { | ||
| std::error_code EC = E.convertToErrorCode(); | ||
| if (EC != errc::permission_denied) | ||
| return errorCodeToError(EC); | ||
| return createStringError( | ||
| EC, Twine("Failed to rename temporary file ") + | ||
| TempFile.TmpName + " to " + ObjectPathName + ": " + | ||
| EC.message() + "\n"); | ||
|
|
||
| auto MBCopy = MemoryBuffer::getMemBufferCopy((*MBOrErr)->getBuffer(), | ||
| ObjectPathName); | ||
|
|
@@ -131,11 +138,22 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef, | |
| }); | ||
|
|
||
| if (E) | ||
| report_fatal_error(Twine("Failed to rename temporary file ") + | ||
| TempFile.TmpName + " to " + ObjectPathName + ": " + | ||
| toString(std::move(E)) + "\n"); | ||
| return E; | ||
|
|
||
| AddBuffer(Task, ModuleName, std::move(*MBOrErr)); | ||
| return Error::success(); | ||
| } | ||
|
|
||
| ~CacheStream() { | ||
| // In Debug builds, try to track down places where commit() was not | ||
| // called before destruction. | ||
| assert(Committed); | ||
|
||
| // In Release builds, fall back to the previous behaviour of committing | ||
| // during destruction and reporting errors with report_fatal_error. | ||
| if (Committed) | ||
| return; | ||
| if (Error Err = commit()) | ||
| report_fatal_error(Twine(toString(std::move(Err)))); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the expectation is that commit() should now always be called, should there be some error detection in the base class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have moved the error detection to the base class.