From: Olivier Goffart Date: Tue, 10 Jul 2018 14:21:45 +0000 (+0200) Subject: Port the invalid napme regexp X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~562 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8bf69cf0cd5845617951877fdc4f8d5b84634f34;p=nextcloud-desktop.git Port the invalid napme regexp TestSyncEngine::testInvalidFilenameRegex --- diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 3b8d27aa5..03d97dbb5 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -171,6 +171,17 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, bool isDirectory) { // FIXME! call directly, without char* conversion auto excluded = _discoveryData->_excludes->csyncTraversalMatchFun()(path.toUtf8(), isDirectory ? ItemTypeDirectory : ItemTypeFile); + + // FIXME: move to ExcludedFiles 's regexp ? + bool isInvalidPattern = false; + if (excluded == CSYNC_NOT_EXCLUDED && !_discoveryData->_invalidFilenamePattern.isEmpty()) { + const QRegExp invalidFilenameRx(_discoveryData->_invalidFilenamePattern); + if (path.contains(invalidFilenameRx)) { + excluded = CSYNC_FILE_EXCLUDE_INVALID_CHAR; + isInvalidPattern = true; + } + } + if (excluded == CSYNC_NOT_EXCLUDED /* FIXME && item->_type != ItemTypeSoftLink */) { return false; } else if (excluded == CSYNC_FILE_SILENTLY_EXCLUDED || excluded == CSYNC_FILE_EXCLUDE_AND_REMOVE) { @@ -208,6 +219,9 @@ bool ProcessDirectoryJob::handleExcluded(const QString &path, bool isDirectory) if (invalid) { item->_errorString = tr("File names containing the character '%1' are not supported on this file system.") .arg(QLatin1Char(invalid)); + } + if (isInvalidPattern) { + item->_errorString = tr("File name contains at least one invalid character"); } else { item->_errorString = tr("The file name is a reserved name on this file system."); } diff --git a/src/libsync/discoveryphase.h b/src/libsync/discoveryphase.h index a0b387104..35973378f 100644 --- a/src/libsync/discoveryphase.h +++ b/src/libsync/discoveryphase.h @@ -109,6 +109,7 @@ public: QStringList _selectiveSyncBlackList; QStringList _selectiveSyncWhiteList; ExcludedFiles *_excludes; + QString _invalidFilenamePattern; // FIXME: maybe move in ExcludedFiles bool isInSelectiveSyncBlackList(const QString &path) const; bool checkSelectiveSyncNewFolder(const QString &path, RemotePermissions rp); diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index 07fbb652e..e564f769e 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -858,11 +858,11 @@ void SyncEngine::slotStartDiscovery() ddata->_account = _account; ddata->_excludes = _excludedFiles.data(); ddata->_statedb = _journal; - ddata->_selectiveSyncBlackList = selectiveSyncBlackList; - ddata->_selectiveSyncWhiteList = _journal->getSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, &ok); ddata->_localDir = _localPath; ddata->_remoteFolder = _remotePath; ddata->_syncOptions = _syncOptions; + ddata->_selectiveSyncBlackList = selectiveSyncBlackList; + ddata->_selectiveSyncWhiteList = _journal->getSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, &ok); if (!ok) { qCWarning(lcEngine) << "Unable to read selective sync list, aborting."; csyncError(tr("Unable to read from the sync journal.")); @@ -870,6 +870,19 @@ void SyncEngine::slotStartDiscovery() return; } + // Check for invalid character in old server version + QString invalidFilenamePattern = _account->capabilities().invalidFilenameRegex(); + if (invalidFilenamePattern.isNull() + && _account->serverVersionInt() < Account::makeServerVersion(8, 1, 0)) { + // Server versions older than 8.1 don't support some characters in filenames. + // If the capability is not set, default to a pattern that avoids uploading + // files with names that contain these. + // It's important to respect the capability also for older servers -- the + // version check doesn't make sense for custom servers. + invalidFilenamePattern = "[\\\\:?*\"<>|]"; + } + ddata->_invalidFilenamePattern = invalidFilenamePattern; + connect(ddata.data(), &DiscoveryPhase::folderDiscovered, this, &SyncEngine::slotFolderDiscovered); connect(ddata.data(), &DiscoveryPhase::newBigFolder, this, &SyncEngine::newBigFolder); @@ -1037,29 +1050,6 @@ void SyncEngine::slotDiscoveryJobFinished(int /*discoveryResult*/) syncItem->_file = adjustRenamedPath(syncItem->_file); } - // Check for invalid character in old server version - QString invalidFilenamePattern = _account->capabilities().invalidFilenameRegex(); - if (invalidFilenamePattern.isNull() - && _account->serverVersionInt() < Account::makeServerVersion(8, 1, 0)) { - // Server versions older than 8.1 don't support some characters in filenames. - // If the capability is not set, default to a pattern that avoids uploading - // files with names that contain these. - // It's important to respect the capability also for older servers -- the - // version check doesn't make sense for custom servers. - invalidFilenamePattern = R"([\:?*"<>|])"; - } - if (!invalidFilenamePattern.isEmpty()) { - const QRegExp invalidFilenameRx(invalidFilenamePattern); - for (const auto &syncItem : qAsConst(syncItems)) { - if (syncItem->_direction == SyncFileItem::Up - && isFileModifyingInstruction(syncItem->_instruction) - && syncItem->destination().contains(invalidFilenameRx)) { - syncItem->_errorString = tr("File name contains at least one invalid character"); - syncItem->_instruction = CSYNC_INSTRUCTION_IGNORE; - } - } - } - ConfigFile cfgFile; if (!_hasNoneFiles && _hasRemoveFile && cfgFile.promptDeleteFiles()) { qCInfo(lcEngine) << "All the files are going to be changed, asking the user";