diff options
Diffstat (limited to 'contrib/llvm/lib/Support/LockFileManager.cpp')
-rw-r--r-- | contrib/llvm/lib/Support/LockFileManager.cpp | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/contrib/llvm/lib/Support/LockFileManager.cpp b/contrib/llvm/lib/Support/LockFileManager.cpp index fb81d60..611f94a 100644 --- a/contrib/llvm/lib/Support/LockFileManager.cpp +++ b/contrib/llvm/lib/Support/LockFileManager.cpp @@ -144,7 +144,9 @@ LockFileManager::LockFileManager(StringRef FileName) { this->FileName = FileName; if (std::error_code EC = sys::fs::make_absolute(this->FileName)) { - Error = EC; + std::string S("failed to obtain absolute path for "); + S.append(this->FileName.str()); + setError(EC, S); return; } LockFileName = this->FileName; @@ -161,7 +163,9 @@ LockFileManager::LockFileManager(StringRef FileName) int UniqueLockFileID; if (std::error_code EC = sys::fs::createUniqueFile( UniqueLockFileName, UniqueLockFileID, UniqueLockFileName)) { - Error = EC; + std::string S("failed to create unique file "); + S.append(UniqueLockFileName.str()); + setError(EC, S); return; } @@ -169,7 +173,7 @@ LockFileManager::LockFileManager(StringRef FileName) { SmallString<256> HostID; if (auto EC = getHostID(HostID)) { - Error = EC; + setError(EC, "failed to get host id"); return; } @@ -185,7 +189,10 @@ 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 = make_error_code(errc::no_space_on_device); + auto EC = make_error_code(errc::no_space_on_device); + std::string S("failed to write to "); + S.append(UniqueLockFileName.str()); + setError(EC, S); sys::fs::remove(UniqueLockFileName); return; } @@ -205,7 +212,10 @@ LockFileManager::LockFileManager(StringRef FileName) } if (EC != errc::file_exists) { - Error = EC; + std::string S("failed to create link "); + raw_string_ostream OSS(S); + OSS << LockFileName.str() << " to " << UniqueLockFileName.str(); + setError(EC, OSS.str()); return; } @@ -226,7 +236,9 @@ LockFileManager::LockFileManager(StringRef FileName) // There is a lock file that nobody owns; try to clean it up and get // ownership. if ((EC = sys::fs::remove(LockFileName))) { - Error = EC; + std::string S("failed to remove lockfile "); + S.append(UniqueLockFileName.str()); + setError(EC, S); return; } } @@ -242,6 +254,19 @@ LockFileManager::LockFileState LockFileManager::getState() const { return LFS_Owned; } +std::string LockFileManager::getErrorMessage() const { + if (Error) { + std::string Str(ErrorDiagMsg); + std::string ErrCodeMsg = Error->message(); + raw_string_ostream OSS(Str); + if (!ErrCodeMsg.empty()) + OSS << ": " << Error->message(); + OSS.flush(); + return Str; + } + return ""; +} + LockFileManager::~LockFileManager() { if (getState() != LFS_Owned) return; |