From 3b208bf838a5f9f2702896116574b87fa8f401b4 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 10 Jul 2023 17:27:58 +0800 Subject: [PATCH] Move trailingSlashPath convenience function into Utility class Signed-off-by: Claudio Cambra --- src/common/utility.cpp | 6 ++++++ src/common/utility.h | 2 ++ src/gui/folder.cpp | 23 +++++++++-------------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/common/utility.cpp b/src/common/utility.cpp index 9baf13777..61f2489e4 100644 --- a/src/common/utility.cpp +++ b/src/common/utility.cpp @@ -723,4 +723,10 @@ bool Utility::isCaseClashConflictFile(const QString &name) return bname.contains(QStringLiteral("(case clash from")); } +QString Utility::trailingSlashPath(const QString &path) +{ + static const auto slash = QLatin1Char('/'); + return path.endsWith(slash) ? path : QString(path + slash); +} + } // namespace OCC diff --git a/src/common/utility.h b/src/common/utility.h index 0dd693f28..b554a196b 100644 --- a/src/common/utility.h +++ b/src/common/utility.h @@ -255,6 +255,8 @@ namespace Utility { */ OCSYNC_EXPORT void registerUriHandlerForLocalEditing(); + OCSYNC_EXPORT QString trailingSlashPath(const QString &path); + #ifdef Q_OS_WIN OCSYNC_EXPORT bool registryKeyExists(HKEY hRootKey, const QString &subKey); OCSYNC_EXPORT QVariant registryGetKeyValue(HKEY hRootKey, const QString &subKey, const QString &valueName); diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 934acd751..f8a60416f 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -52,11 +52,6 @@ namespace { #define VERSION_C constexpr auto versionC = "version"; #endif - -QString trailingSlashPath(const QString &path) -{ - return path.endsWith('/') ? path : QString(path + QStringLiteral("/")); -} } namespace OCC { @@ -177,7 +172,7 @@ void Folder::checkLocalPath() _canonicalLocalPath = _definition.localPath; } - _canonicalLocalPath = trailingSlashPath(_canonicalLocalPath); + _canonicalLocalPath = Utility::trailingSlashPath(_canonicalLocalPath); if (fi.isDir() && fi.isReadable()) { qCDebug(lcFolder) << "Checked local path ok"; @@ -222,7 +217,7 @@ QString Folder::path() const QString Folder::shortGuiLocalPath() const { QString p = _definition.localPath; - const auto home = trailingSlashPath(QDir::homePath()); + const auto home = Utility::trailingSlashPath(QDir::homePath()); if (p.startsWith(home)) { p = p.mid(home.length()); @@ -272,7 +267,7 @@ QString Folder::remotePath() const QString Folder::remotePathTrailingSlash() const { - return trailingSlashPath(remotePath()); + return Utility::trailingSlashPath(remotePath()); } QUrl Folder::remoteUrl() const @@ -845,7 +840,7 @@ bool Folder::pathIsIgnored(const QString &path) const void Folder::appendPathToSelectiveSyncList(const QString &path, const SyncJournalDb::SelectiveSyncListType listType) { - const auto folderPath = trailingSlashPath(path); + const auto folderPath = Utility::trailingSlashPath(path); const auto journal = journalDb(); auto ok = false; auto list = journal->getSelectiveSyncList(listType, &ok); @@ -858,7 +853,7 @@ void Folder::appendPathToSelectiveSyncList(const QString &path, const SyncJourna void Folder::removePathFromSelectiveSyncList(const QString &path, const SyncJournalDb::SelectiveSyncListType listType) { - const auto folderPath = trailingSlashPath(path); + const auto folderPath = Utility::trailingSlashPath(path); const auto journal = journalDb(); auto ok = false; auto list = journal->getSelectiveSyncList(listType, &ok); @@ -1226,7 +1221,7 @@ void Folder::slotItemCompleted(const SyncFileItemPtr &item, ErrorCategory errorC void Folder::slotNewBigFolderDiscovered(const QString &newF, bool isExternal) { - const auto newFolder = trailingSlashPath(newF); + const auto newFolder = Utility::trailingSlashPath(newF); auto journal = journalDb(); // Add the entry to the blacklist if it is neither in the blacklist or whitelist already @@ -1260,7 +1255,7 @@ void Folder::slotNewBigFolderDiscovered(const QString &newF, bool isExternal) void Folder::slotExistingFolderNowBig(const QString &folderPath) { - const auto trailSlashFolderPath = trailingSlashPath(folderPath); + const auto trailSlashFolderPath = Utility::trailingSlashPath(folderPath); const auto journal = journalDb(); // Add the entry to the whitelist if it is neither in the blacklist or whitelist already @@ -1547,7 +1542,7 @@ void Folder::removeLocalE2eFiles() } if (!parentPathEncrypted) { - const auto pathAdjusted = trailingSlashPath(rec._path); + const auto pathAdjusted = Utility::trailingSlashPath(rec._path); e2eFoldersToBlacklist.append(pathAdjusted); } } @@ -1663,7 +1658,7 @@ bool FolderDefinition::load(QSettings &settings, const QString &alias, QString FolderDefinition::prepareLocalPath(const QString &path) { const auto normalisedPath = QDir::fromNativeSeparators(path); - return trailingSlashPath(normalisedPath); + return Utility::trailingSlashPath(normalisedPath); } QString FolderDefinition::prepareTargetPath(const QString &path) -- 2.30.2