| 20 | |
| 21 | using namespace platform; |
| 22 | ExclusiveLock::ExclusiveLock(const std::string &folder, const std::string &file) { |
| 23 | std::string full_path = folder + "/" + file; |
| 24 | #if !TARGET_OS_IPHONE // We do not need lock on iOS because only 1 instance of app will be running |
| 25 | #ifdef _WIN32 |
| 26 | auto wfull_path = FileStream::utf8_to_utf16(expand_path(full_path)); |
| 27 | handle = CreateFileW(wfull_path.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); |
| 28 | if (handle == INVALID_HANDLE_VALUE) |
| 29 | #else |
| 30 | fd = open(expand_path(full_path).c_str(), O_CREAT | O_WRONLY, 0600); |
| 31 | int status = lockf(fd, F_TLOCK, 4096); |
| 32 | if (status != 0) |
| 33 | #endif |
| 34 | throw FailedToLock("ExclusiveLock fail at path=" + full_path); |
| 35 | #endif |
| 36 | } |
| 37 | |
| 38 | ExclusiveLock::~ExclusiveLock() { |
| 39 | #if !TARGET_OS_IPHONE |
nothing calls this directly
no test coverage detected