LockFileManager::readLockFile(StringRef LockFileName) {
// Check whether the lock file exists. If not, clearly there's nothing
// to read, so we just return.
- bool Exists = false;
- if (sys::fs::exists(LockFileName, Exists) || !Exists)
+ if (!sys::fs::exists(LockFileName))
return None;
// 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.
OwningPtr<MemoryBuffer> MB;
- if (MemoryBuffer::getFile(LockFileName, MB)) {
- StringRef Hostname;
- StringRef PIDStr;
- tie(Hostname, PIDStr) = getToken(MB->getBuffer(), " ");
- int PID;
- if (PIDStr.getAsInteger(10, PID))
- return std::make_pair(std::string(Hostname), PID);
- }
+ if (MemoryBuffer::getFile(LockFileName, MB))
+ return None;
+
+ StringRef Hostname;
+ StringRef PIDStr;
+ std::tie(Hostname, PIDStr) = getToken(MB->getBuffer(), " ");
+ PIDStr = PIDStr.substr(PIDStr.find_first_not_of(" "));
+ int PID;
+ if (!PIDStr.getAsInteger(10, PID))
+ return std::make_pair(std::string(Hostname), PID);
// Delete the lock file. It's invalid anyway.
sys::fs::remove(LockFileName);
// 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);
- bool Existed;
- sys::fs::remove(UniqueLockFileName.c_str(), Existed);
+ sys::fs::remove(UniqueLockFileName.c_str());
return;
}
}
// Someone else managed to create the lock file first. Wipe out our unique
// lock file (it's useless now) and read the process ID from the lock file.
- bool Existed;
- sys::fs::remove(UniqueLockFileName.str(), Existed);
+ sys::fs::remove(UniqueLockFileName.str());
if ((Owner = readLockFile(LockFileName)))
return;
// There is a lock file that nobody owns; try to clean it up and report
// an error.
- sys::fs::remove(LockFileName.str(), Existed);
+ sys::fs::remove(LockFileName.str());
Error = EC;
}
return;
// Since we own the lock, remove the lock file and our own unique lock file.
- bool Existed;
- sys::fs::remove(LockFileName.str(), Existed);
- sys::fs::remove(UniqueLockFileName.str(), Existed);
+ sys::fs::remove(LockFileName.str());
+ sys::fs::remove(UniqueLockFileName.str());
}
void LockFileManager::waitForUnlock() {
#else
nanosleep(&Interval, NULL);
#endif
- bool Exists = false;
bool LockFileJustDisappeared = false;
// If the lock file is still expected to be there, check whether it still
// is.
if (!LockFileGone) {
+ bool Exists;
if (!sys::fs::exists(LockFileName.str(), Exists) && !Exists) {
LockFileGone = true;
LockFileJustDisappeared = true;
- Exists = false;
}
}
// If the lock file is no longer there, check if the original file is
// available now.
if (LockFileGone) {
- if (!sys::fs::exists(FileName.str(), Exists) && Exists) {
+ if (sys::fs::exists(FileName.str())) {
return;
}