mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[LockFileManager] Improve error output by using better error messages
This is currently used by clang to lock access to modules; improve the error message so that clang can use better output messages from locking error issues. rdar://problem/26529101 Differential Review: http://reviews.llvm.org/D20942 llvm-svn: 271755
This commit is contained in:
parent
718ab049bc
commit
396da704c4
@ -57,6 +57,7 @@ private:
|
||||
|
||||
Optional<std::pair<std::string, int> > Owner;
|
||||
Optional<std::error_code> Error;
|
||||
std::string ErrorDiagMsg;
|
||||
|
||||
LockFileManager(const LockFileManager &) = delete;
|
||||
LockFileManager &operator=(const LockFileManager &) = delete;
|
||||
@ -82,6 +83,15 @@ public:
|
||||
/// \brief Remove the lock file. This may delete a different lock file than
|
||||
/// the one previously read if there is a race.
|
||||
std::error_code unsafeRemoveLockFile();
|
||||
|
||||
/// \brief Get error message, or "" if there is no error.
|
||||
std::string getErrorMessage() const;
|
||||
|
||||
/// \brief Set error and error message
|
||||
void setError(std::error_code &EC, StringRef ErrorMsg = "") {
|
||||
Error = EC;
|
||||
ErrorDiagMsg = ErrorMsg.str();
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user