[Support] Allow discarding a FileOutputBuffer without removing the memory mapping

Differential Revision: https://reviews.llvm.org/D51095

llvm-svn: 340634
This commit is contained in:
Martin Storsjo 2018-08-24 18:36:22 +00:00
parent 147119c3ce
commit 084c5476f3
2 changed files with 10 additions and 0 deletions

View File

@ -76,6 +76,10 @@ public:
/// deallocates the buffer and the target file is never written.
virtual ~FileOutputBuffer() {}
/// This removes the temporary file (unless it already was committed)
/// but keeps the memory mapping alive.
virtual void discard() {}
protected:
FileOutputBuffer(StringRef Path) : FinalPath(Path) {}

View File

@ -61,6 +61,12 @@ public:
consumeError(Temp.discard());
}
void discard() override {
// Delete the temp file if it still was open, but keeping the mapping
// active.
consumeError(Temp.discard());
}
private:
std::unique_ptr<fs::mapped_file_region> Buffer;
fs::TempFile Temp;