|
KiCad PCB EDA Suite
|
Advisory lock over a file, taken by writing a sibling lock file and holding an exclusive lock on it for as long as this object lives. More...
#include <lockfile.h>
Public Member Functions | |
| LOCKFILE (const wxString &filename, bool aRemoveOnRelease=true) | |
| LOCKFILE (LOCKFILE &&other) noexcept | |
| ~LOCKFILE () | |
| void | UnlockFile () |
| Unlock and remove the file from the filesystem as long as we still own it. | |
| bool | OverrideLock (bool aRemoveOnRelease=true) |
| Force the lock, overwriting the data that existed already. | |
| bool | IsLockedByMe () |
| wxString | GetUsername () |
| wxString | GetHostname () |
| bool | Locked () const |
| bool | Valid () const |
Static Public Member Functions | |
| static LOCKFILE | Inspect (const wxString &aFilename) |
| Look at a lock without taking it: nothing is created, nothing is claimed and nothing is removed on release, so a caller that only wants to know who holds a lock cannot disturb it. | |
| static wxString | LockPathFor (const wxString &aFilename) |
Private Member Functions | |
| LOCKFILE ()=default | |
| void | claim () |
| bool | readRecord (nlohmann::json &aRecord) const |
| void | readOwner () |
| bool | stillOwnLock () |
Static Private Member Functions | |
| static wxString | newToken () |
Private Attributes | |
| wxString | m_lockFilename |
| wxString | m_username |
| wxString | m_hostname |
| wxString | m_token |
| KIPLATFORM::IO::FILE_LOCK | m_lock |
| bool | m_owned = false |
| bool | m_status = false |
| bool | m_removeOnRelease = false |
Advisory lock over a file, taken by writing a sibling lock file and holding an exclusive lock on it for as long as this object lives.
The operating system drops that lock when the owning process dies, so a lock file we can lock is one whose writer is gone and whose contents we may take over. That keeps a session killed by a crash from pinning its project read-only forever, without ever guessing at the liveness of a process we cannot see.
Definition at line 53 of file lockfile.h.
|
inline |
Definition at line 56 of file lockfile.h.
References KIPLATFORM::IO::FILE_LOCK::BUSY, claim(), KIPLATFORM::IO::FILE_LOCK::HELD, IsLockedByMe(), KIPLATFORM::ENV::IsRemovablePath(), LockPathFor(), m_lock, m_lockFilename, m_removeOnRelease, m_status, readOwner(), and traceLockFile.
Referenced by Inspect(), and LOCKFILE().
|
inlinenoexcept |
Definition at line 143 of file lockfile.h.
References LOCKFILE().
|
inline |
Definition at line 157 of file lockfile.h.
References UnlockFile().
|
privatedefault |
|
inlineprivate |
Definition at line 255 of file lockfile.h.
References m_hostname, m_lock, m_lockFilename, m_owned, m_status, m_token, m_username, newToken(), and traceLockFile.
Referenced by LOCKFILE(), and OverrideLock().
|
inline |
Definition at line 220 of file lockfile.h.
References m_hostname.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), KICAD_MANAGER_FRAME::LoadProject(), and KICAD_MANAGER_FRAME::ProjectChanged().
|
inline |
Definition at line 214 of file lockfile.h.
References m_username.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), KICAD_MANAGER_FRAME::LoadProject(), and KICAD_MANAGER_FRAME::ProjectChanged().
|
inlinestatic |
Look at a lock without taking it: nothing is created, nothing is claimed and nothing is removed on release, so a caller that only wants to know who holds a lock cannot disturb it.
Valid() then answers whether the lock is free rather than whether we hold it, and Locked() is always false.
Definition at line 113 of file lockfile.h.
References LOCKFILE(), LockPathFor(), m_lock, m_lockFilename, m_status, KIPLATFORM::IO::FILE_LOCK::OpenForInspect(), and readOwner().
Referenced by HISTORY_LOCK_MANAGER::acquireFileLock(), HISTORY_LOCK_MANAGER::IsLockStale(), KICAD_MANAGER_FRAME::LoadProject(), and SETTINGS_MANAGER::LoadProject().
|
inline |
Definition at line 200 of file lockfile.h.
References m_hostname, and m_username.
Referenced by BOOST_AUTO_TEST_CASE(), and LOCKFILE().
|
inline |
Definition at line 222 of file lockfile.h.
References m_owned.
Referenced by BOOST_AUTO_TEST_CASE(), and HISTORY_LOCK_MANAGER::BreakStaleLock().
|
inlinestatic |
Definition at line 134 of file lockfile.h.
References FILEEXT::LockFileExtension, and FILEEXT::LockFilePrefix.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), Inspect(), HISTORY_LOCK_MANAGER::IsLockStale(), LOCKFILE(), and seedLockedProject().
|
inlinestaticprivate |
Definition at line 243 of file lockfile.h.
Referenced by claim().
|
inline |
Force the lock, overwriting the data that existed already.
Definition at line 188 of file lockfile.h.
References claim(), m_lock, m_lockFilename, m_owned, m_removeOnRelease, m_status, and traceLockFile.
Referenced by KICAD_MANAGER_FRAME::LoadProject(), and KICAD_MANAGER_FRAME::ProjectChanged().
|
inlineprivate |
Definition at line 300 of file lockfile.h.
References m_hostname, m_token, m_username, and readRecord().
Referenced by Inspect(), and LOCKFILE().
|
inlineprivate |
Definition at line 282 of file lockfile.h.
References m_lock, m_lockFilename, and traceLockFile.
Referenced by readOwner(), and stillOwnLock().
|
inlineprivate |
Definition at line 327 of file lockfile.h.
References m_lockFilename, m_token, readRecord(), and traceLockFile.
Referenced by UnlockFile().
|
inline |
Unlock and remove the file from the filesystem as long as we still own it.
Definition at line 165 of file lockfile.h.
References m_lock, m_lockFilename, m_owned, m_removeOnRelease, m_status, stillOwnLock(), and traceLockFile.
Referenced by ~LOCKFILE().
|
inline |
Definition at line 224 of file lockfile.h.
References m_status.
Referenced by HISTORY_LOCK_MANAGER::acquireFileLock(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), HISTORY_LOCK_MANAGER::IsLockStale(), KICAD_MANAGER_FRAME::LoadProject(), SETTINGS_MANAGER::LoadProject(), and KICAD_MANAGER_FRAME::ProjectChanged().
|
private |
Definition at line 232 of file lockfile.h.
Referenced by claim(), GetHostname(), IsLockedByMe(), and readOwner().
|
private |
Definition at line 234 of file lockfile.h.
Referenced by claim(), Inspect(), LOCKFILE(), OverrideLock(), readRecord(), and UnlockFile().
|
private |
Definition at line 230 of file lockfile.h.
Referenced by claim(), Inspect(), LOCKFILE(), OverrideLock(), readRecord(), stillOwnLock(), and UnlockFile().
|
private |
Definition at line 235 of file lockfile.h.
Referenced by claim(), Locked(), OverrideLock(), and UnlockFile().
|
private |
Definition at line 237 of file lockfile.h.
Referenced by LOCKFILE(), OverrideLock(), and UnlockFile().
|
private |
Definition at line 236 of file lockfile.h.
Referenced by claim(), Inspect(), LOCKFILE(), OverrideLock(), UnlockFile(), and Valid().
|
private |
Definition at line 233 of file lockfile.h.
Referenced by claim(), readOwner(), and stillOwnLock().
|
private |
Definition at line 231 of file lockfile.h.
Referenced by claim(), GetUsername(), IsLockedByMe(), and readOwner().