From: Claudio Cambra Date: Mon, 10 Jul 2023 09:51:24 +0000 (+0800) Subject: Replace all manual isntancesof adding trailing slash with use of utility method X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~92^2^2~57^2~15 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=21656cce17463a6d74665b465b694f78a892b535;p=nextcloud-desktop.git Replace all manual isntancesof adding trailing slash with use of utility method Signed-off-by: Claudio Cambra --- diff --git a/src/common/syncjournaldb.cpp b/src/common/syncjournaldb.cpp index c58bd695e..03719c6d2 100644 --- a/src/common/syncjournaldb.cpp +++ b/src/common/syncjournaldb.cpp @@ -1985,10 +1985,7 @@ QStringList SyncJournalDb::getSelectiveSyncList(SyncJournalDb::SelectiveSyncList if (!next.hasData) break; - auto entry = query->stringValue(0); - if (!entry.endsWith(QLatin1Char('/'))) { - entry.append(QLatin1Char('/')); - } + const auto entry = Utility::trailingSlashPath(query->stringValue(0)); result.append(entry); } *ok = true; diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 2009412d6..cc300174d 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -1514,7 +1514,7 @@ void AccountSettings::refreshSelectiveSyncStatus() // FIXME: add the folder alias in a hoover hint. // folder->alias() + QLatin1String("/") - const auto folderTrailingSlash = it.endsWith('/') ? it : it + QChar('/'); + const auto folderTrailingSlash = Utility::trailingSlashPath(it); const auto folderWithoutTrailingSlash = it.endsWith('/') ? it.left(it.length() - 1) : it; const auto escapedFolderString = Utility::escape(folderWithoutTrailingSlash); const auto escapedFolderName = Utility::escape(folder->alias()); diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index 8a92b291a..061efc862 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -13,12 +13,13 @@ */ #include "folderstatusmodel.h" -#include "folderman.h" #include "accountstate.h" #include "common/asserts.h" -#include -#include +#include "common/utility.h" +#include "folderman.h" #include "folderstatusdelegate.h" +#include +#include #include #include @@ -703,9 +704,7 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list) parentInfo->_fetched = true; QUrl url = parentInfo->_folder->remoteUrl(); - QString pathToRemove = url.path(); - if (!pathToRemove.endsWith('/')) - pathToRemove += '/'; + const auto pathToRemove = Utility::trailingSlashPath(url.path()); QStringList selectiveSyncBlackList; bool ok1 = true; diff --git a/src/gui/folderwatcher_win.h b/src/gui/folderwatcher_win.h index d72665f06..6c4a261e0 100644 --- a/src/gui/folderwatcher_win.h +++ b/src/gui/folderwatcher_win.h @@ -15,8 +15,9 @@ #ifndef MIRALL_FOLDERWATCHER_WIN_H #define MIRALL_FOLDERWATCHER_WIN_H -#include +#include "common/utility.h" #include +#include #include namespace OCC { @@ -33,7 +34,7 @@ class WatcherThread : public QThread public: WatcherThread(const QString &path) : QThread() - , _path(path + (path.endsWith(QLatin1Char('/')) ? QString() : QStringLiteral("/"))) + , _path(Utility::trailingSlashPath(path)) , _directory(0) , _resultEvent(0) , _stopEvent(0) diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp index 551fc487d..b0354b58e 100644 --- a/src/gui/owncloudsetupwizard.cpp +++ b/src/gui/owncloudsetupwizard.cpp @@ -20,19 +20,20 @@ #include #include -#include "wizard/owncloudwizardcommon.h" -#include "wizard/owncloudwizard.h" -#include "owncloudsetupwizard.h" -#include "configfile.h" -#include "folderman.h" #include "accessmanager.h" #include "account.h" -#include "networkjobs.h" -#include "sslerrordialog.h" #include "accountmanager.h" #include "clientproxy.h" +#include "common/utility.h" +#include "configfile.h" #include "filesystem.h" +#include "folderman.h" +#include "networkjobs.h" #include "owncloudgui.h" +#include "owncloudsetupwizard.h" +#include "sslerrordialog.h" +#include "wizard/owncloudwizard.h" +#include "wizard/owncloudwizardcommon.h" #include "creds/credentialsfactory.h" #include "creds/abstractcredentials.h" @@ -125,13 +126,7 @@ void OwncloudSetupWizard::startWizard() } // remember the local folder to compare later if it changed, but clean first - QString lf = QDir::fromNativeSeparators(localFolder); - if (!lf.endsWith(QLatin1Char('/'))) { - lf.append(QLatin1Char('/')); - } - - _initLocalFolder = lf; - + _initLocalFolder = Utility::trailingSlashPath(QDir::fromNativeSeparators(localFolder)); _ocWizard->setRemoteFolder(_remoteFolder); const auto isEnforcedServerSetup = diff --git a/src/gui/selectivesyncdialog.cpp b/src/gui/selectivesyncdialog.cpp index 4f4ca1ec1..d83d1b9cd 100644 --- a/src/gui/selectivesyncdialog.cpp +++ b/src/gui/selectivesyncdialog.cpp @@ -12,23 +12,23 @@ * for more details. */ #include "selectivesyncdialog.h" -#include "folder.h" #include "account.h" +#include "common/utility.h" +#include "configfile.h" +#include "folder.h" +#include "folderman.h" #include "networkjobs.h" #include "theme.h" -#include "folderman.h" -#include "configfile.h" #include -#include -#include -#include #include #include -#include +#include #include +#include +#include #include -#include #include +#include namespace OCC { @@ -203,10 +203,7 @@ void SelectiveSyncWidget::slotUpdateDirectories(QStringList list) auto *root = dynamic_cast(_folderTree->topLevelItem(0)); QUrl url = _account->davUrl(); - QString pathToRemove = url.path(); - if (!pathToRemove.endsWith('/')) { - pathToRemove.append('/'); - } + auto pathToRemove = Utility::trailingSlashPath(url.path()); pathToRemove.append(_folderPath); if (!_folderPath.isEmpty()) pathToRemove.append('/'); diff --git a/src/gui/socketapi/socketuploadjob.cpp b/src/gui/socketapi/socketuploadjob.cpp index b8ee787a1..6e4ebc968 100644 --- a/src/gui/socketapi/socketuploadjob.cpp +++ b/src/gui/socketapi/socketuploadjob.cpp @@ -13,6 +13,7 @@ */ #include "socketuploadjob.h" +#include "common/utility.h" #include "socketapi_p.h" #include "accountmanager.h" @@ -55,7 +56,7 @@ SocketUploadJob::SocketUploadJob(const QSharedPointer &job) SyncOptions opt; opt.fillFromEnvironmentVariables(); opt.verifyChunkSizes(); - _engine = new SyncEngine(account->account(), _localPath.endsWith(QLatin1Char('/')) ? _localPath : _localPath + QLatin1Char('/'), opt, _remotePath, _db); + _engine = new SyncEngine(account->account(), Utility::trailingSlashPath(_localPath), opt, _remotePath, _db); _engine->setParent(_db); connect(_engine, &OCC::SyncEngine::itemCompleted, this, [this](const OCC::SyncFileItemPtr item) { diff --git a/src/gui/wizard/webviewpage.cpp b/src/gui/wizard/webviewpage.cpp index 0b5ccd9ca..8e492ea27 100644 --- a/src/gui/wizard/webviewpage.cpp +++ b/src/gui/wizard/webviewpage.cpp @@ -6,10 +6,11 @@ #include #include -#include "owncloudwizard.h" +#include "account.h" +#include "common/utility.h" #include "creds/webflowcredentials.h" +#include "owncloudwizard.h" #include "webview.h" -#include "account.h" namespace OCC { @@ -46,11 +47,7 @@ void WebViewPage::initializePage() { if (_ocWizard->registration()) { url = "https://nextcloud.com/register"; } else { - url = _ocWizard->ocUrl(); - if (!url.endsWith('/')) { - url += "/"; - } - url += "index.php/login/flow"; + url = Utility::trailingSlashPath(_ocWizard->ocUrl()) + "index.php/login/flow"; } qCInfo(lcWizardWebiewPage()) << "Url to auth at: " << url; _webView->setUrl(QUrl(url)); diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 86e39d956..5bbcc817d 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -363,11 +363,8 @@ QString ConfigFile::configPath() const _confDir = newLocation; } } - QString dir = _confDir; - if (!dir.endsWith(QLatin1Char('/'))) - dir.append(QLatin1Char('/')); - return dir; + return Utility::trailingSlashPath(_confDir); } static const QLatin1String exclFile("sync-exclude.lst"); diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 936193094..8d24b56f6 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -437,7 +437,7 @@ void ProcessDirectoryJob::checkAndUpdateSelectiveSyncListsForE2eeFolders(const Q { bool ok = false; - const auto pathWithTrailingSpace = path.endsWith(QLatin1Char('/')) ? path : path + QLatin1Char('/'); + const auto pathWithTrailingSpace = Utility::trailingSlashPath(path); auto blackListSet = _discoveryData->_statedb->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok).toSet(); blackListSet.insert(pathWithTrailingSpace); diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp index e992159a9..9034da4b0 100644 --- a/src/libsync/discoveryphase.cpp +++ b/src/libsync/discoveryphase.cpp @@ -13,6 +13,7 @@ */ #include "discoveryphase.h" +#include "common/utility.h" #include "configfile.h" #include "discovery.h" #include "helpers.h" @@ -122,8 +123,7 @@ void DiscoveryPhase::checkSelectiveSyncNewFolder(const QString &path, } // it is not too big, put it in the white list (so we will not do more query for the children) and and do not block. - static const auto slash = QLatin1Char('/'); - const auto sanitisedPath = path.endsWith(slash) ? path : path + slash; + const auto sanitisedPath = Utility::trailingSlashPath(path); _selectiveSyncWhiteList.insert(std::upper_bound(_selectiveSyncWhiteList.begin(), _selectiveSyncWhiteList.end(), sanitisedPath), sanitisedPath); return callback(false); }); diff --git a/src/libsync/owncloudpropagator.h b/src/libsync/owncloudpropagator.h index f38291b1e..e837641a4 100644 --- a/src/libsync/owncloudpropagator.h +++ b/src/libsync/owncloudpropagator.h @@ -25,13 +25,14 @@ #include #include +#include "accountfwd.h" +#include "bandwidthmanager.h" +#include "common/syncjournaldb.h" +#include "common/utility.h" #include "csync.h" +#include "progressdispatcher.h" #include "syncfileitem.h" -#include "common/syncjournaldb.h" -#include "bandwidthmanager.h" -#include "accountfwd.h" #include "syncoptions.h" -#include "progressdispatcher.h" #include @@ -416,15 +417,13 @@ public: bool _finishedEmited = false; // used to ensure that finished is only emitted once public: - OwncloudPropagator(AccountPtr account, const QString &localDir, - const QString &remoteFolder, SyncJournalDb *progressDb, - QSet &bulkUploadBlackList) + OwncloudPropagator(AccountPtr account, const QString &localDir, const QString &remoteFolder, SyncJournalDb *progressDb, QSet &bulkUploadBlackList) : _journal(progressDb) , _bandwidthManager(this) , _chunkSize(10 * 1000 * 1000) // 10 MB, overridden in setSyncOptions , _account(account) - , _localDir((localDir.endsWith(QChar('/'))) ? localDir : localDir + '/') - , _remoteFolder((remoteFolder.endsWith(QChar('/'))) ? remoteFolder : remoteFolder + '/') + , _localDir(Utility::trailingSlashPath(localDir)) + , _remoteFolder(Utility::trailingSlashPath(remoteFolder)) , _bulkUploadBlackList(bulkUploadBlackList) { qRegisterMetaType("PropagatorJob::AbortType"); diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index b4fadc453..52985fd44 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -617,12 +617,8 @@ void SyncEngine::startSync() _discoveryPhase->_excludes->reloadExcludeFiles(); } _discoveryPhase->_statedb = _journal; - _discoveryPhase->_localDir = _localPath; - if (!_discoveryPhase->_localDir.endsWith('/')) - _discoveryPhase->_localDir+='/'; - _discoveryPhase->_remoteFolder = _remotePath; - if (!_discoveryPhase->_remoteFolder.endsWith('/')) - _discoveryPhase->_remoteFolder+='/'; + _discoveryPhase->_localDir = Utility::trailingSlashPath(_localPath); + _discoveryPhase->_remoteFolder = Utility::trailingSlashPath(_remotePath); _discoveryPhase->_syncOptions = _syncOptions; _discoveryPhase->_shouldDiscoverLocaly = [this](const QString &path) { const auto result = shouldDiscoverLocally(path); diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index a8bcd1273..fb589c29d 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -408,12 +408,12 @@ QString Theme::helpUrl() const QString Theme::conflictHelpUrl() const { - auto baseUrl = helpUrl(); - if (baseUrl.isEmpty()) + const auto baseUrl = helpUrl(); + if (baseUrl.isEmpty()) { return QString(); - if (!baseUrl.endsWith('/')) - baseUrl.append('/'); - return baseUrl + QStringLiteral("conflicts.html"); + } + + return Utility::trailingSlashPath(baseUrl) + QStringLiteral("conflicts.html"); } QString Theme::overrideServerUrl() const diff --git a/test/syncenginetestutils.cpp b/test/syncenginetestutils.cpp index 15c7f5a48..76617d751 100644 --- a/test/syncenginetestutils.cpp +++ b/test/syncenginetestutils.cpp @@ -6,9 +6,10 @@ */ #include "syncenginetestutils.h" -#include "httplogger.h" #include "accessmanager.h" +#include "common/utility.h" #include "gui/sharepermissions.h" +#include "httplogger.h" #include #include @@ -285,11 +286,7 @@ QString FileInfo::path() const QString FileInfo::absolutePath() const { - if (parentPath.endsWith(QLatin1Char('/'))) { - return parentPath + name; - } else { - return parentPath + QLatin1Char('/') + name; - } + return OCC::Utility::trailingSlashPath(parentPath) + name; } void FileInfo::fixupParentPathRecursively() @@ -339,10 +336,7 @@ FakePropfindReply::FakePropfindReply(FileInfo &remoteRootFileInfo, QNetworkAcces auto writeFileResponse = [&](const FileInfo &fileInfo) { xml.writeStartElement(davUri, QStringLiteral("response")); - auto url = QString::fromUtf8(QUrl::toPercentEncoding(fileInfo.absolutePath(), "/")); - if (!url.endsWith(QChar('/'))) { - url.append(QChar('/')); - } + const auto url = OCC::Utility::trailingSlashPath(QString::fromUtf8(QUrl::toPercentEncoding(fileInfo.absolutePath(), "/"))); const auto href = OCC::Utility::concatUrlPath(prefix, url).path(); xml.writeTextElement(davUri, QStringLiteral("href"), href); xml.writeStartElement(davUri, QStringLiteral("propstat")); @@ -1178,9 +1172,7 @@ FileInfo FakeFolder::currentLocalState() QString FakeFolder::localPath() const { // SyncEngine wants a trailing slash - if (_tempDir.path().endsWith(QLatin1Char('/'))) - return _tempDir.path(); - return _tempDir.path() + QLatin1Char('/'); + return OCC::Utility::trailingSlashPath(_tempDir.path()); } void FakeFolder::scheduleSync()