From cb6358048db10e77280e8dd820d52ed9c8213cff Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 8 May 2023 16:21:54 -0500 Subject: [PATCH] fix: does not trash added torrent files when asked (#5505) --- qt/Session.cc | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/qt/Session.cc b/qt/Session.cc index 9967801f5..55df8f262 100644 --- a/qt/Session.cc +++ b/qt/Session.cc @@ -1040,7 +1040,7 @@ void Session::addTorrent(AddData add_me, tr_variant* args_dict, bool trash_origi }); q->add( - [this, add_me](RpcResponse const& r) + [this, add_me, trash_original](RpcResponse const& r) { bool session_has_torrent = false; @@ -1060,23 +1060,23 @@ void Session::addTorrent(AddData add_me, tr_variant* args_dict, bool trash_origi } } - if (session_has_torrent && !add_me.filename.isEmpty()) + if (auto const& filename = add_me.filename; + session_has_torrent && !filename.isEmpty() && add_me.type == AddData::FILENAME) { - QFile(add_me.filename).rename(QStringLiteral("%1.added").arg(add_me.filename)); + auto file = QFile{ filename }; + + if (trash_original) + { + file.setPermissions(QFile::ReadOwner | QFile::WriteOwner); + file.remove(); + } + else + { + file.rename(QStringLiteral("%1.added").arg(filename)); + } } }); - if (trash_original && add_me.type == AddData::FILENAME) - { - q->add( - [add_me]() - { - QFile original(add_me.filename); - original.setPermissions(QFile::ReadOwner | QFile::WriteOwner); - original.remove(); - }); - } - q->run(); }