diff options
author | ckamm <mail@ckamm.de> | 2016-04-29 17:14:18 +0300 |
---|---|---|
committer | Klaas Freitag <freitag@owncloud.com> | 2016-04-29 17:14:18 +0300 |
commit | e6b937f508a78d6eae3e9d187d70271535d23d86 (patch) | |
tree | 3b5db20231d7a8bfd4ab947baec318685a075528 /src/gui/lockwatcher.cpp | |
parent | 31c13f74fbc2149fd9e58a5796dc17bb209440fb (diff) |
LockWatcher: Keep an eye on Windows file locks (#4758)
When a conflict-rename or a temporary-rename fails, notify the
LockWatcher. It'll regularly check whether the file has become
accesible again. When it has, another sync is triggered.
owncloud/enterprise#1288
Diffstat (limited to 'src/gui/lockwatcher.cpp')
-rw-r--r-- | src/gui/lockwatcher.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/gui/lockwatcher.cpp b/src/gui/lockwatcher.cpp new file mode 100644 index 000000000..7b1247990 --- /dev/null +++ b/src/gui/lockwatcher.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) by Christian Kamm <mail@ckamm.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "lockwatcher.h" +#include "filesystem.h" + +#include <QTimer> + +using namespace OCC; + +static const int check_frequency = 20 * 1000; // ms + +LockWatcher::LockWatcher(QObject* parent) + : QObject(parent) +{ + connect(&_timer, SIGNAL(timeout()), + SLOT(checkFiles())); + _timer.start(check_frequency); +} + +void LockWatcher::addFile(const QString& path) +{ + _watchedPaths.insert(path); +} + +void LockWatcher::checkFiles() +{ + QSet<QString> unlocked; + + foreach (const QString& path, _watchedPaths) { + if (!FileSystem::isFileLocked(path)) { + 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); +} |