[clang] [clang] Introduce `ModuleCache::write()` (PR #188877)
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 31 09:09:12 PDT 2026
================
@@ -101,6 +101,39 @@ void clang::maybePruneImpl(StringRef Path, time_t PruneInterval,
}
}
+std::error_code clang::writeImpl(StringRef Path, llvm::MemoryBufferRef Buffer) {
+ StringRef Extension = llvm::sys::path::extension(Path);
+ SmallString<128> ModelPath = StringRef(Path).drop_back(Extension.size());
+ ModelPath += "-%%%%%%%%";
+ ModelPath += Extension;
+ ModelPath += ".tmp";
+
+ std::error_code EC;
+ int FD;
+ SmallString<128> TmpPath;
+ if ((EC = llvm::sys::fs::createUniqueFile(ModelPath, FD, TmpPath))) {
----------------
jansvoboda11 wrote:
If we wrote to the final destination directly, readers might observe a partially-written PCM file and erroring out. Renaming a file is atomic, so writing to a temporary file and then renaming the file to the final name is the way to implement atomic file writes.
https://github.com/llvm/llvm-project/pull/188877
More information about the cfe-commits
mailing list