Update the MemoryBuffer API to use ErrorOr.
[oota-llvm.git] / lib / Support / LockFileManager.cpp
index 0ca631cb63466d61c2d1085a3720efe646ccbd93..3f224e0c588f77f7987cc230267d3630b4b4405c 100644 (file)
@@ -9,6 +9,7 @@
 #include "llvm/Support/LockFileManager.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
@@ -32,11 +33,13 @@ Optional<std::pair<std::string, int> >
 LockFileManager::readLockFile(StringRef LockFileName) {
   // Read the owning host and PID out of the lock file. If it appears that the
   // owning process is dead, the lock file is invalid.
-  std::unique_ptr<MemoryBuffer> MB;
-  if (MemoryBuffer::getFile(LockFileName, MB)) {
+  ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
+      MemoryBuffer::getFile(LockFileName);
+  if (!MBOrErr) {
     sys::fs::remove(LockFileName);
     return None;
   }
+  std::unique_ptr<MemoryBuffer> MB = std::move(MBOrErr.get());
 
   StringRef Hostname;
   StringRef PIDStr;
@@ -112,7 +115,7 @@ LockFileManager::LockFileManager(StringRef FileName)
     if (Out.has_error()) {
       // We failed to write out PID, so make up an excuse, remove the
       // unique lock file, and fail.
-      Error = std::make_error_code(std::errc::no_space_on_device);
+      Error = make_error_code(errc::no_space_on_device);
       sys::fs::remove(UniqueLockFileName.c_str());
       return;
     }
@@ -125,7 +128,7 @@ LockFileManager::LockFileManager(StringRef FileName)
     if (!EC)
       return;
 
-    if (EC != std::errc::file_exists) {
+    if (EC != errc::file_exists) {
       Error = EC;
       return;
     }