-
Notifications
You must be signed in to change notification settings - Fork 920
Expand file tree
/
Copy pathlockwatcher.cpp
More file actions
59 lines (47 loc) · 1.5 KB
/
lockwatcher.cpp
File metadata and controls
59 lines (47 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud GmbH
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "lockwatcher.h"
#include "filesystem.h"
#include <QLoggingCategory>
#include <QTimer>
using namespace OCC;
Q_LOGGING_CATEGORY(lcLockWatcher, "nextcloud.gui.lockwatcher", QtInfoMsg)
static const int check_frequency = 20 * 1000; // ms
LockWatcher::LockWatcher(QObject *parent)
: QObject(parent)
{
connect(&_timer, &QTimer::timeout,
this, &LockWatcher::checkFiles);
_timer.start(check_frequency);
}
void LockWatcher::addFile(const QString &path)
{
qCInfo(lcLockWatcher) << "Watching for lock of" << path << "being released";
_watchedPaths.insert(path);
}
void LockWatcher::setCheckInterval(std::chrono::milliseconds interval)
{
_timer.start(interval.count());
}
bool LockWatcher::contains(const QString &path)
{
return _watchedPaths.contains(path);
}
void LockWatcher::checkFiles()
{
QSet<QString> unlocked;
for (const auto &path : std::as_const(_watchedPaths)) {
if (!FileSystem::isFileLocked(path, FileSystem::LockMode::SharedRead)) {
qCInfo(lcLockWatcher) << "Lock of" << path << "was released";
emit fileUnlocked(path);
unlocked.insert(path);
}
}
// Doing it this way instead of with a QMutableSetIterator
// ensures that calling back into addFile from connected
// slots isn't a problem.
_watchedPaths.subtract(unlocked);
}