KiCad PCB EDA Suite
Loading...
Searching...
No Matches
history_lock.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef HISTORY_LOCK_H
21#define HISTORY_LOCK_H
22
23#include <memory>
24#include <wx/string.h>
25
26struct git_repository;
27struct git_index;
28class LOCKFILE;
29
57{
58public:
67 HISTORY_LOCK_MANAGER( const wxString& aProjectPath, int aStaleTimeoutSec = 0 );
68
73
74 // Non-copyable
77
83 bool IsLocked() const;
84
90 git_repository* GetRepository() { return m_repo; }
91
97 git_index* GetIndex() { return m_index; }
98
104 wxString GetLockError() const;
105
111 wxString GetLockHolder() const;
112
122 static bool IsLockStale( const wxString& aProjectPath, int aStaleTimeoutSec = 0 );
123
131 static bool BreakStaleLock( const wxString& aProjectPath );
132
136 void ReleaseRepository();
137
138private:
141 std::unique_ptr<LOCKFILE> m_fileLock;
142 git_repository* m_repo;
143 git_index* m_index;
146 wxString m_lockError;
148
149 bool acquireFileLock();
150 bool openRepository();
151 bool acquireIndexLock();
152};
153
154#endif // HISTORY_LOCK_H
wxString GetLockHolder() const
Get information about who currently holds the lock.
HISTORY_LOCK_MANAGER(const wxString &aProjectPath, int aStaleTimeoutSec=0)
Construct a lock manager and attempt to acquire locks.
git_repository * GetRepository()
Get the git repository handle (only valid if IsLocked() returns true).
void ReleaseRepository()
Release git repository and index handles early, but keep the file lock.
~HISTORY_LOCK_MANAGER()
Destructor releases all locks and closes git repository.
wxString GetLockError() const
Get error message describing why lock could not be acquired.
git_repository * m_repo
git_index * GetIndex()
Get the git index handle (only valid if IsLocked() returns true).
static bool BreakStaleLock(const wxString &aProjectPath)
Forcibly remove a stale lock file.
HISTORY_LOCK_MANAGER(const HISTORY_LOCK_MANAGER &)=delete
std::unique_ptr< LOCKFILE > m_fileLock
static bool IsLockStale(const wxString &aProjectPath, int aStaleTimeoutSec=0)
Check if a lock file exists and is stale (older than timeout).
HISTORY_LOCK_MANAGER & operator=(const HISTORY_LOCK_MANAGER &)=delete
bool IsLocked() const
Check if locks were successfully acquired.