[PATCH] D55417: [clangd] Change disk-backed storage to be atomic

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 13 03:39:46 PST 2018


ilya-biryukov added inline comments.


================
Comment at: clangd/index/BackgroundIndexStorage.cpp:42
+  llvm::Twine TempPath(OutPath, ".tmp.");
+  TempPath.concat(std::to_string(rand()));
+  std::error_code EC;
----------------
There's a helper in LLVM that will do this, `llvm::createUniqueFile()`, I believe it also tries multiple times in case of clashes.


================
Comment at: clangd/index/BackgroundIndexStorage.cpp:55
+  // Then move to real location.
+  EC = llvm::sys::fs::rename(TempPath, OutPath);
+  if (EC)
----------------
We **should not** remove if no error occurred, as the same name at this point can be taken by a different action.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55417/new/

https://reviews.llvm.org/D55417





More information about the cfe-commits mailing list