Skip to content

Commit

Permalink
ensure correct behavioron Windows for invalid file names
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
  • Loading branch information
mgallien committed Feb 18, 2025
1 parent 76ec847 commit ea6279a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,11 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, const Entries &ent
|| excluded == CSYNC_FILE_EXCLUDE_LEADING_AND_TRAILING_SPACE;

const auto leadingAndTrailingSpacesFilesAllowed = !_discoveryData->_shouldEnforceWindowsFileNameCompatibility || _discoveryData->_leadingAndTrailingSpacesFilesAllowed.contains(_discoveryData->_localDir + path);
#if defined Q_OS_WINDOWS
if (hasLeadingOrTrailingSpaces && leadingAndTrailingSpacesFilesAllowed) {
#else
if (hasLeadingOrTrailingSpaces && (wasSyncedAlready || leadingAndTrailingSpacesFilesAllowed)) {
#endif
excluded = CSYNC_NOT_EXCLUDED;
}

Expand Down
4 changes: 4 additions & 0 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,10 @@ void SyncEngine::startSync()
_shouldEnforceWindowsFileNameCompatibility = true;
_discoveryPhase->_shouldEnforceWindowsFileNameCompatibility = _shouldEnforceWindowsFileNameCompatibility;
}
#if defined Q_OS_WINDOWS
_shouldEnforceWindowsFileNameCompatibility = true;
_discoveryPhase->_shouldEnforceWindowsFileNameCompatibility = _shouldEnforceWindowsFileNameCompatibility;
#endif

// Check for invalid character in old server version
QString invalidFilenamePattern = _account->capabilities().invalidFilenameRegex();
Expand Down
4 changes: 3 additions & 1 deletion test/testlocaldiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ private slots:
fakeFolder.syncEngine().setLocalDiscoveryOptions(LocalDiscoveryStyle::DatabaseAndFilesystem, {QStringLiteral("foo"), QStringLiteral("bar"), QStringLiteral("bla"), QStringLiteral("A/foo"), QStringLiteral("A/bar"), QStringLiteral("A/bla")});
QVERIFY(fakeFolder.syncOnce());

#if defined Q_OS_WINDOWS
#if !defined Q_OS_WINDOWS
QCOMPARE(completeSpy.findItem(fileWithSpaces1)->_status, SyncFileItem::Status::Success);
QCOMPARE(completeSpy.findItem(fileWithSpaces2)->_status, SyncFileItem::Status::Success);
QCOMPARE(completeSpy.findItem(fileWithSpaces3)->_status, SyncFileItem::Status::Success);
Expand Down Expand Up @@ -605,9 +605,11 @@ private slots:

QVERIFY(fakeFolder.syncOnce());

#if !defined Q_OS_WINDOWS
auto expectedState = fakeFolder.currentLocalState();
qDebug() << expectedState;
QCOMPARE(fakeFolder.currentRemoteState(), expectedState);
#endif
}

void testBlockInvalidMtimeSyncRemote()
Expand Down

0 comments on commit ea6279a

Please sign in to comment.