diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 6e290fa1b..37bfb0576 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -993,23 +993,25 @@ bool SessionImpl::editCategory(const QString &name, const CategoryOptions &optio if (options == currentOptions) return false; - currentOptions = options; - storeCategories(); if (isDisableAutoTMMWhenCategorySavePathChanged()) { + // This should be done before changing the category options + // to prevent the torrent from being moved at the new save path. + for (TorrentImpl *const torrent : asConst(m_torrents)) { if (torrent->category() == name) torrent->setAutoTMMEnabled(false); } } - else + + currentOptions = options; + storeCategories(); + + for (TorrentImpl *const torrent : asConst(m_torrents)) { - for (TorrentImpl *const torrent : asConst(m_torrents)) - { - if (torrent->category() == name) - torrent->handleCategoryOptionsChanged(); - } + if (torrent->category() == name) + torrent->handleCategoryOptionsChanged(); } emit categoryOptionsChanged(name); @@ -3277,6 +3279,9 @@ void SessionImpl::setSavePath(const Path &path) if (isDisableAutoTMMWhenDefaultSavePathChanged()) { + // This should be done before changing the save path + // to prevent the torrent from being moved at the new save path. + QSet affectedCatogories {{}}; // includes default (unnamed) category for (auto it = m_categories.cbegin(); it != m_categories.cend(); ++it) { @@ -3314,6 +3319,9 @@ void SessionImpl::setDownloadPath(const Path &path) if (isDisableAutoTMMWhenDefaultSavePathChanged()) { + // This should be done before changing the save path + // to prevent the torrent from being moved at the new save path. + QSet affectedCatogories {{}}; // includes default (unnamed) category for (auto it = m_categories.cbegin(); it != m_categories.cend(); ++it) { diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index af1afc498..45cc7f3bf 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1615,18 +1615,20 @@ bool TorrentImpl::setCategory(const QString &category) if (!category.isEmpty() && !m_session->categories().contains(category)) return false; + if (m_session->isDisableAutoTMMWhenCategoryChanged()) + { + // This should be done before changing the category name + // to prevent the torrent from being moved at the path of new category. + setAutoTMMEnabled(false); + } + const QString oldCategory = m_category; m_category = category; deferredRequestResumeData(); m_session->handleTorrentCategoryChanged(this, oldCategory); if (m_useAutoTMM) - { - if (!m_session->isDisableAutoTMMWhenCategoryChanged()) - adjustStorageLocation(); - else - setAutoTMMEnabled(false); - } + adjustStorageLocation(); } return true;