| 41 | } |
| 42 | |
| 43 | cmFileLockResult cmFileLock::Lock(std::string const& filename, |
| 44 | unsigned long timeout) |
| 45 | { |
| 46 | if (filename.empty()) { |
| 47 | // Error is internal since all the directories and file must be created |
| 48 | // before actual lock called. |
| 49 | return cmFileLockResult::MakeInternal(); |
| 50 | } |
| 51 | |
| 52 | if (!this->Filename.empty()) { |
| 53 | // Error is internal since double-lock must be checked in class |
| 54 | // cmFileLockPool by the cmFileLock::IsLocked method. |
| 55 | return cmFileLockResult::MakeInternal(); |
| 56 | } |
| 57 | |
| 58 | this->Filename = filename; |
| 59 | cmFileLockResult result = this->OpenFile(); |
| 60 | if (result.IsOk()) { |
| 61 | if (timeout == static_cast<unsigned long>(-1)) { |
| 62 | result = this->LockWithoutTimeout(); |
| 63 | } else { |
| 64 | result = this->LockWithTimeout(timeout); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | if (!result.IsOk()) { |
| 69 | this->Filename.clear(); |
| 70 | } |
| 71 | |
| 72 | return result; |
| 73 | } |
| 74 | |
| 75 | bool cmFileLock::IsLocked(std::string const& filename) const |
| 76 | { |
no test coverage detected