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 <kicommon.h>
24
25#include <memory>
26#include <wx/string.h>
27
28struct git_repository;
29struct git_index;
30class LOCKFILE;
31
59{
60public:
69 HISTORY_LOCK_MANAGER( const wxString& aProjectPath, int aStaleTimeoutSec = 0 );
70
75
76 // Non-copyable
79
85 bool IsLocked() const;
86
92 git_repository* GetRepository() { return m_repo; }
93
99 git_index* GetIndex() { return m_index; }
100
106 wxString GetLockError() const;
107
113 wxString GetLockHolder() const;
114
124 static bool IsLockStale( const wxString& aProjectPath, int aStaleTimeoutSec = 0 );
125
133 static bool BreakStaleLock( const wxString& aProjectPath );
134
138 void ReleaseRepository();
139
140private:
143 std::unique_ptr<LOCKFILE> m_fileLock;
144 git_repository* m_repo;
145 git_index* m_index;
148 wxString m_lockError;
150
151 bool acquireFileLock();
152 bool openRepository();
153 bool acquireIndexLock();
154};
155
156#endif // HISTORY_LOCK_H
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).
git_repository * m_repo
git_index * GetIndex()
Get the git index handle (only valid if IsLocked() returns true).
HISTORY_LOCK_MANAGER(const HISTORY_LOCK_MANAGER &)=delete
std::unique_ptr< LOCKFILE > m_fileLock
HISTORY_LOCK_MANAGER & operator=(const HISTORY_LOCK_MANAGER &)=delete
bool IsLocked() const
Check if locks were successfully acquired.
Advisory lock over a file, taken by writing a sibling lock file and holding an exclusive lock on it f...
Definition lockfile.h:60
#define KICOMMON_API
Definition kicommon.h:27