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, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef HISTORY_LOCK_H
25#define HISTORY_LOCK_H
26
27#include <memory>
28#include <wx/string.h>
29
30struct git_repository;
31struct git_index;
32class LOCKFILE;
33
61{
62public:
71 HISTORY_LOCK_MANAGER( const wxString& aProjectPath, int aStaleTimeoutSec = 0 );
72
77
78 // Non-copyable
81
87 bool IsLocked() const;
88
94 git_repository* GetRepository() { return m_repo; }
95
101 git_index* GetIndex() { return m_index; }
102
108 wxString GetLockError() const;
109
115 wxString GetLockHolder() const;
116
126 static bool IsLockStale( const wxString& aProjectPath, int aStaleTimeoutSec = 0 );
127
135 static bool BreakStaleLock( const wxString& aProjectPath );
136
137private:
140 std::unique_ptr<LOCKFILE> m_fileLock;
141 git_repository* m_repo;
142 git_index* m_index;
145 wxString m_lockError;
147
148 bool acquireFileLock();
149 bool openRepository();
150 bool acquireIndexLock();
151};
152
153#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).
~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.