#include "llvm/Support/LockFileManager.h"
#include "llvm/ADT/None.h"
+#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Errc.h"
return true;
}
-namespace {
-
-/// An RAII helper object for cleanups.
-class RAIICleanup {
- std::function<void()> Fn;
- bool Canceled = false;
-
-public:
- RAIICleanup(std::function<void()> Fn) : Fn(Fn) {}
-
- ~RAIICleanup() {
- if (Canceled)
- return;
- Fn();
- }
-
- void cancel() { Canceled = true; }
-};
-
-} // end anonymous namespace
-
LockFileManager::LockFileManager(StringRef FileName)
{
this->FileName = FileName;
UniqueLockFile = std::move(*Temp);
// Make sure we discard the temporary file on exit.
- RAIICleanup RemoveTempFile([&]() {
+ auto RemoveTempFile = llvm::make_scope_exit([&]() {
if (Error E = UniqueLockFile->discard())
setError(errorToErrorCode(std::move(E)));
});
std::error_code EC =
sys::fs::create_link(UniqueLockFile->TmpName, LockFileName);
if (!EC) {
- RemoveTempFile.cancel();
+ RemoveTempFile.release();
return;
}