From 699b91ab8d99ada8fc84213cd1b79069242133f4 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Mon, 12 Jul 2021 11:44:52 +0300 Subject: [PATCH] Properly create "clean path" for watched folder (#15179) --- src/base/torrentfileswatcher.cpp | 5 ++--- src/gui/watchedfoldersmodel.cpp | 16 +++++++--------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/base/torrentfileswatcher.cpp b/src/base/torrentfileswatcher.cpp index 2a0d63917..24f7c478a 100644 --- a/src/base/torrentfileswatcher.cpp +++ b/src/base/torrentfileswatcher.cpp @@ -268,11 +268,10 @@ QString TorrentFilesWatcher::makeCleanPath(const QString &path) if (path.isEmpty()) throw InvalidArgument(tr("Watched folder path cannot be empty.")); - const QDir dir {path}; - if (dir.isRelative()) + if (QDir::isRelativePath(path)) throw InvalidArgument(tr("Watched folder path cannot be relative.")); - return dir.canonicalPath(); + return QDir::cleanPath(path); } void TorrentFilesWatcher::load() diff --git a/src/gui/watchedfoldersmodel.cpp b/src/gui/watchedfoldersmodel.cpp index aa1d9459e..0a3a5dd5f 100644 --- a/src/gui/watchedfoldersmodel.cpp +++ b/src/gui/watchedfoldersmodel.cpp @@ -102,23 +102,21 @@ bool WatchedFoldersModel::removeRows(const int row, const int count, const QMode void WatchedFoldersModel::addFolder(const QString &path, const TorrentFilesWatcher::WatchedFolderOptions &options) { - if (path.isEmpty()) - throw InvalidArgument(tr("Watched folder path cannot be empty.")); - - const QDir watchDir {path}; - const QString canonicalWatchPath = watchDir.canonicalPath(); - if (m_watchedFoldersOptions.contains(canonicalWatchPath)) + const QString cleanWatchPath = m_fsWatcher->makeCleanPath(path); + if (m_watchedFoldersOptions.contains(cleanWatchPath)) throw RuntimeError(tr("Folder '%1' is already in watch list.").arg(path)); + + const QDir watchDir {cleanWatchPath}; if (!watchDir.exists()) throw RuntimeError(tr("Folder '%1' doesn't exist.").arg(path)); if (!watchDir.isReadable()) throw RuntimeError(tr("Folder '%1' isn't readable.").arg(path)); - m_deletedFolders.remove(canonicalWatchPath); + m_deletedFolders.remove(cleanWatchPath); beginInsertRows(QModelIndex(), rowCount(), rowCount()); - m_watchedFolders.append(canonicalWatchPath); - m_watchedFoldersOptions[canonicalWatchPath] = options; + m_watchedFolders.append(cleanWatchPath); + m_watchedFoldersOptions[cleanWatchPath] = options; endInsertRows(); }