================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to