Move trailingSlashPath convenience function into Utility class
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 10 Jul 2023 09:27:58 +0000 (17:27 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Fri, 4 Aug 2023 09:40:42 +0000 (17:40 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/common/utility.cpp
src/common/utility.h
src/gui/folder.cpp

index 9baf1377720f226aa3a7b9ebcb2d7c350e2b54aa..61f2489e4255bb5a1866a3eeca4f6ee271ca6117 100644 (file)
@@ -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
index 0dd693f284a71a2ebe750fd1212a3ced5abf9ed0..b554a196be189b2fd9ee1f02fdf76207fdc3b167 100644 (file)
@@ -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);
index 934acd75196555b9d7abdd96801fe712466f7562..f8a60416f1bcda461b86b3734fcbb1ca0b7753fc 100644 (file)
@@ -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)