Skip to content

Commit 5a6ea43

Browse files
committed
fix(lockedFiles): try to silently ignore locked files
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
1 parent 867bd30 commit 5a6ea43

4 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/csync/csync_exclude.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include <QFileInfo>
2828
#include <QDir>
2929
#include <QVariant>
30+
#include <QLoggingCategory>
31+
32+
Q_LOGGING_CATEGORY(lcCsyncExclude, "nextcloud.csync.exclude", QtInfoMsg)
3033

3134
/** Expands C-like escape sequences (in place)
3235
*/
@@ -163,10 +166,16 @@ static CSYNC_EXCLUDE_TYPE _csync_excluded_common(const QString &path, bool exclu
163166
// not allow to sync those to avoid file loss/ambiguities (#416)
164167
if (blen > 1) {
165168
if (bname.at(blen - 1) == QLatin1Char('.')) {
169+
166170
return CSYNC_FILE_EXCLUDE_INVALID_CHAR;
167171
}
168172
}
169173

174+
if (OCC::FileSystem::isFileLocked(path, OCC::FileSystem::LockMode::SharedRead)) {
175+
qCWarning(lcCsyncExclude) << path << "is locked" << "exluding it from sync";
176+
return CSYNC_FILE_LOCKED_SILENTLY_EXCLUDED;
177+
}
178+
170179
if (csync_is_windows_reserved_word(bname)) {
171180
return CSYNC_FILE_SILENTLY_EXCLUDED;
172181
}

src/gui/folder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,11 @@ bool Folder::pathIsIgnored(const QString &path) const
10011001
return true;
10021002
}
10031003

1004+
if (OCC::FileSystem::isFileLocked(path, OCC::FileSystem::LockMode::SharedRead)) {
1005+
qCDebug(lcFolder) << path << "is locked" << "skip syncing it";
1006+
return true;
1007+
}
1008+
10041009
#ifndef OWNCLOUD_TEST
10051010
if (isFileExcludedAbsolute(path) && !Utility::isConflictFile(path)) {
10061011
qCDebug(lcFolder) << "* Ignoring file" << path;

src/libsync/discovery.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, const Entries &ent
259259

260260
auto excluded = _discoveryData->_excludes->traversalPatternMatch(path, isDirectory ? ItemTypeDirectory : ItemTypeFile);
261261

262+
if (OCC::FileSystem::isFileLocked(_discoveryData->_localDir + path, OCC::FileSystem::LockMode::SharedRead)) {
263+
qCInfo(lcDisco) << _discoveryData->_localDir + path << "is locked" << "exluding it from sync";
264+
excluded = CSYNC_FILE_SILENTLY_EXCLUDED;
265+
}
266+
262267
const auto fileName = path.mid(path.lastIndexOf('/') + 1);
263268

264269
const auto isLocal = entries.localEntry.isValid();

test/testlockedfiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private slots:
137137

138138
fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::DatabaseAndFilesystem, tracker.localDiscoveryPaths());
139139
tracker.startSyncPartialDiscovery();
140-
QVERIFY(!fakeFolder.syncOnce());
140+
QVERIFY(fakeFolder.syncOnce());
141141

142142
QVERIFY(seenLockedFiles.contains(fakeFolder.localPath() + "A/a1"));
143143
QVERIFY(seenLockedFiles.size() == 1);

0 commit comments

Comments
 (0)