Skip to content

Commit 6259d06

Browse files
committed
chore: only ignore locked files when uploading them
fix behavior to match expectations from existing automated tests ignoring locked files that would have been uploaded (i.e. not downloaded) ignoring locked files that have not match another ignore rule Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
1 parent e3b82aa commit 6259d06

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/csync/csync_exclude.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ enum CSYNC_EXCLUDE_TYPE {
3737
CSYNC_FILE_EXCLUDE_SERVER_BLACKLISTED,
3838
CSYNC_FILE_EXCLUDE_LEADING_SPACE,
3939
CSYNC_FILE_EXCLUDE_LEADING_AND_TRAILING_SPACE,
40+
CSYNC_FILE_LOCKED_SILENTLY_EXCLUDED,
4041
};
4142

4243
class ExcludedFilesTest;

src/libsync/discovery.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,6 @@ 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-
emit _discoveryData->seenLockedFile(path);
267-
}
268-
269262
const auto fileName = path.mid(path.lastIndexOf('/') + 1);
270263

271264
const auto isLocal = entries.localEntry.isValid();
@@ -361,6 +354,14 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, const Entries &ent
361354
}
362355
}
363356

357+
if (excluded == CSYNC_NOT_EXCLUDED && OCC::FileSystem::isFileLocked(_discoveryData->_localDir + path, OCC::FileSystem::LockMode::SharedRead) &&
358+
(!entries.dbEntry.isValid() || !entries.serverEntry.isValid() || entries.serverEntry.etag == entries.dbEntry._etag)) {
359+
qCInfo(lcDisco) << _discoveryData->_localDir + path << "is locked" << "exluding it from sync";
360+
excluded = CSYNC_FILE_LOCKED_SILENTLY_EXCLUDED;
361+
362+
emit _discoveryData->seenLockedFile(_discoveryData->_localDir + path);
363+
}
364+
364365
if (excluded == CSYNC_NOT_EXCLUDED && !entries.localEntry.isSymLink) {
365366
return false;
366367
} else if (excluded == CSYNC_FILE_SILENTLY_EXCLUDED || excluded == CSYNC_FILE_EXCLUDE_AND_REMOVE) {
@@ -391,6 +392,9 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, const Entries &ent
391392
case CSYNC_FILE_EXCLUDE_AND_REMOVE:
392393
qCFatal(lcDisco) << "These were handled earlier";
393394
break;
395+
case CSYNC_FILE_LOCKED_SILENTLY_EXCLUDED:
396+
item->_errorString = tr("File is locked by another application.");
397+
break;
394398
case CSYNC_FILE_EXCLUDE_LIST:
395399
item->_errorString = tr("File is listed on the ignore list.");
396400
break;
@@ -2463,6 +2467,7 @@ bool ProcessDirectoryJob::maybeRenameForWindowsCompatibility(const QString &abso
24632467
switch (excludeReason)
24642468
{
24652469
case CSYNC_NOT_EXCLUDED:
2470+
case CSYNC_FILE_LOCKED_SILENTLY_EXCLUDED:
24662471
case CSYNC_FILE_EXCLUDE_CASE_CLASH_CONFLICT:
24672472
case CSYNC_FILE_EXCLUDE_AND_REMOVE:
24682473
case CSYNC_FILE_EXCLUDE_CANNOT_ENCODE:

test/testlockedfiles.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ private slots:
141141

142142
QVERIFY(seenLockedFiles.contains(fakeFolder.localPath() + "A/a1"));
143143
QVERIFY(seenLockedFiles.size() == 1);
144-
QVERIFY(hasLocalDiscoveryPath("A/a1"));
144+
QVERIFY(!hasLocalDiscoveryPath("A/a1"));
145145

146146
CloseHandle(h1);
147147

148-
fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::DatabaseAndFilesystem, tracker.localDiscoveryPaths());
148+
fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::DatabaseAndFilesystem, {"A/a1"});
149149
tracker.startSyncPartialDiscovery();
150150
QVERIFY(fakeFolder.syncOnce());
151151
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

0 commit comments

Comments
 (0)