mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 13:53:37 -07:00
Fix .torrent file could not be deleted when torrent is canceled
PR #21735. Closes #21723.
This commit is contained in:
parent
fe24bc825b
commit
6079b25419
5 changed files with 19 additions and 11 deletions
|
@ -195,11 +195,9 @@ void AddTorrentManager::setTorrentFileGuard(const QString &source, std::shared_p
|
||||||
m_guardedTorrentFiles.emplace(source, std::move(torrentFileGuard));
|
m_guardedTorrentFiles.emplace(source, std::move(torrentFileGuard));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddTorrentManager::releaseTorrentFileGuard(const QString &source)
|
std::shared_ptr<TorrentFileGuard> AddTorrentManager::releaseTorrentFileGuard(const QString &source)
|
||||||
{
|
{
|
||||||
auto torrentFileGuard = m_guardedTorrentFiles.take(source);
|
return m_guardedTorrentFiles.take(source);
|
||||||
if (torrentFileGuard)
|
|
||||||
torrentFileGuard->setAutoRemove(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AddTorrentManager::processTorrent(const QString &source, const BitTorrent::TorrentDescriptor &torrentDescr
|
bool AddTorrentManager::processTorrent(const QString &source, const BitTorrent::TorrentDescriptor &torrentDescr
|
||||||
|
|
|
@ -74,7 +74,7 @@ protected:
|
||||||
void handleAddTorrentFailed(const QString &source, const QString &reason);
|
void handleAddTorrentFailed(const QString &source, const QString &reason);
|
||||||
void handleDuplicateTorrent(const QString &source, const BitTorrent::TorrentDescriptor &torrentDescr, BitTorrent::Torrent *existingTorrent);
|
void handleDuplicateTorrent(const QString &source, const BitTorrent::TorrentDescriptor &torrentDescr, BitTorrent::Torrent *existingTorrent);
|
||||||
void setTorrentFileGuard(const QString &source, std::shared_ptr<TorrentFileGuard> torrentFileGuard);
|
void setTorrentFileGuard(const QString &source, std::shared_ptr<TorrentFileGuard> torrentFileGuard);
|
||||||
void releaseTorrentFileGuard(const QString &source);
|
std::shared_ptr<TorrentFileGuard> releaseTorrentFileGuard(const QString &source);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onDownloadFinished(const Net::DownloadResult &result);
|
void onDownloadFinished(const Net::DownloadResult &result);
|
||||||
|
|
|
@ -821,6 +821,8 @@ void AddNewTorrentDialog::reject()
|
||||||
if (!m_currentContext) [[unlikely]]
|
if (!m_currentContext) [[unlikely]]
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
emit torrentRejected(m_currentContext->torrentDescr);
|
||||||
|
|
||||||
const BitTorrent::TorrentDescriptor &torrentDescr = m_currentContext->torrentDescr;
|
const BitTorrent::TorrentDescriptor &torrentDescr = m_currentContext->torrentDescr;
|
||||||
const bool hasMetadata = torrentDescr.info().has_value();
|
const bool hasMetadata = torrentDescr.info().has_value();
|
||||||
if (!hasMetadata)
|
if (!hasMetadata)
|
||||||
|
|
|
@ -66,6 +66,7 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void torrentAccepted(const BitTorrent::TorrentDescriptor &torrentDescriptor, const BitTorrent::AddTorrentParams &addTorrentParams);
|
void torrentAccepted(const BitTorrent::TorrentDescriptor &torrentDescriptor, const BitTorrent::AddTorrentParams &addTorrentParams);
|
||||||
|
void torrentRejected(const BitTorrent::TorrentDescriptor &torrentDescriptor);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateDiskSpaceLabel();
|
void updateDiskSpaceLabel();
|
||||||
|
|
|
@ -235,15 +235,22 @@ bool GUIAddTorrentManager::processTorrent(const QString &source
|
||||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
m_dialogs[infoHash] = dlg;
|
m_dialogs[infoHash] = dlg;
|
||||||
connect(dlg, &AddNewTorrentDialog::torrentAccepted, this
|
connect(dlg, &AddNewTorrentDialog::torrentAccepted, this
|
||||||
, [this, source](const BitTorrent::TorrentDescriptor &torrentDescr, const BitTorrent::AddTorrentParams &addTorrentParams)
|
, [this, source, dlg](const BitTorrent::TorrentDescriptor &torrentDescr, const BitTorrent::AddTorrentParams &addTorrentParams)
|
||||||
{
|
|
||||||
addTorrentToSession(source, torrentDescr, addTorrentParams);
|
|
||||||
});
|
|
||||||
connect(dlg, &QDialog::finished, this, [this, source, infoHash, dlg]
|
|
||||||
{
|
{
|
||||||
if (dlg->isDoNotDeleteTorrentChecked())
|
if (dlg->isDoNotDeleteTorrentChecked())
|
||||||
releaseTorrentFileGuard(source);
|
{
|
||||||
|
if (auto torrentFileGuard = releaseTorrentFileGuard(source))
|
||||||
|
torrentFileGuard->setAutoRemove(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
addTorrentToSession(source, torrentDescr, addTorrentParams);
|
||||||
|
});
|
||||||
|
connect(dlg, &AddNewTorrentDialog::torrentRejected, this, [this, source]
|
||||||
|
{
|
||||||
|
releaseTorrentFileGuard(source);
|
||||||
|
});
|
||||||
|
connect(dlg, &QDialog::finished, this, [this, source, infoHash]
|
||||||
|
{
|
||||||
m_dialogs.remove(infoHash);
|
m_dialogs.remove(infoHash);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue