Add user data parameter for torrent removal callback (#4009)

This commit is contained in:
Mike Gelfand
2022-10-23 17:51:35 +01:00
committed by GitHub
parent f0a0b855c6
commit 70f623f32b
9 changed files with 24 additions and 17 deletions

View File

@@ -99,7 +99,7 @@ void OptionsDialog::Impl::removeOldTorrent()
if (tor_ != nullptr) if (tor_ != nullptr)
{ {
file_list_->clear(); file_list_->clear();
tr_torrentRemove(tor_, false, nullptr); tr_torrentRemove(tor_, false, nullptr, nullptr);
tor_ = nullptr; tor_ = nullptr;
} }
} }

View File

@@ -1265,7 +1265,9 @@ void Session::remove_torrent(tr_torrent_id_t id, bool delete_local_data)
tr_torrentRemove( tr_torrentRemove(
tor, tor,
delete_local_data, delete_local_data,
[](char const* filename, tr_error** error) { return gtr_file_trash_or_remove(filename, error); }); [](char const* filename, void* /*user_data*/, tr_error** error)
{ return gtr_file_trash_or_remove(filename, error); },
nullptr);
} }
} }

View File

@@ -296,7 +296,7 @@ static char const* torrentRemove(
{ {
if (auto const status = session->rpcNotify(type, tor); (status & TR_RPC_NOREMOVE) == 0) if (auto const status = session->rpcNotify(type, tor); (status & TR_RPC_NOREMOVE) == 0)
{ {
tr_torrentRemove(tor, delete_flag, nullptr); tr_torrentRemove(tor, delete_flag, nullptr, nullptr);
} }
} }

View File

@@ -1623,7 +1623,12 @@ void tr_torrentFree(tr_torrent* tor)
} }
} }
static void removeTorrentInEventThread(tr_torrent* tor, bool delete_flag, tr_fileFunc delete_func) static bool removeTorrentFile(char const* filename, void* /*user_data*/, tr_error** error)
{
return tr_sys_path_remove(filename, error);
}
static void removeTorrentInEventThread(tr_torrent* tor, bool delete_flag, tr_fileFunc delete_func, void* user_data)
{ {
auto const lock = tor->unique_lock(); auto const lock = tor->unique_lock();
@@ -1635,12 +1640,12 @@ static void removeTorrentInEventThread(tr_torrent* tor, bool delete_flag, tr_fil
if (delete_func == nullptr) if (delete_func == nullptr)
{ {
delete_func = tr_sys_path_remove; delete_func = removeTorrentFile;
} }
auto const delete_func_wrapper = [&delete_func](char const* filename) auto const delete_func_wrapper = [&delete_func, user_data](char const* filename)
{ {
delete_func(filename, nullptr); delete_func(filename, user_data, nullptr);
}; };
tor->metainfo_.files().remove(tor->currentDir(), tor->name(), delete_func_wrapper); tor->metainfo_.files().remove(tor->currentDir(), tor->name(), delete_func_wrapper);
} }
@@ -1648,13 +1653,13 @@ static void removeTorrentInEventThread(tr_torrent* tor, bool delete_flag, tr_fil
closeTorrent(tor); closeTorrent(tor);
} }
void tr_torrentRemove(tr_torrent* tor, bool delete_flag, tr_fileFunc delete_func) void tr_torrentRemove(tr_torrent* tor, bool delete_flag, tr_fileFunc delete_func, void* user_data)
{ {
TR_ASSERT(tr_isTorrent(tor)); TR_ASSERT(tr_isTorrent(tor));
tor->isDeleting = true; tor->isDeleting = true;
tr_runInEventThread(tor->session, removeTorrentInEventThread, tor, delete_flag, delete_func); tr_runInEventThread(tor->session, removeTorrentInEventThread, tor, delete_flag, delete_func, user_data);
} }
/** /**

View File

@@ -872,10 +872,10 @@ tr_torrent* tr_torrentNew(tr_ctor* ctor, tr_torrent** setme_duplicate_of);
/** @addtogroup tr_torrent Torrents /** @addtogroup tr_torrent Torrents
@{ */ @{ */
using tr_fileFunc = bool (*)(char const* filename, struct tr_error** error); using tr_fileFunc = bool (*)(char const* filename, void* user_data, struct tr_error** error);
/** @brief Removes our torrent and .resume files for this torrent */ /** @brief Removes our torrent and .resume files for this torrent */
void tr_torrentRemove(tr_torrent* torrent, bool delete_flag, tr_fileFunc delete_func); void tr_torrentRemove(tr_torrent* torrent, bool delete_flag, tr_fileFunc delete_func, void* user_data);
/** @brief Start a torrent */ /** @brief Start a torrent */
void tr_torrentStart(tr_torrent* torrent); void tr_torrentStart(tr_torrent* torrent);

View File

@@ -101,7 +101,7 @@ void renameCallback(tr_torrent* torrent, char const* oldPathCharString, char con
} }
} }
bool trashDataFile(char const* filename, tr_error** error) bool trashDataFile(char const* filename, void* /*user_data*/, tr_error** error)
{ {
if (filename == NULL) if (filename == NULL)
{ {
@@ -213,7 +213,7 @@ bool trashDataFile(char const* filename, tr_error** error)
//allow the file to be indexed by Time Machine //allow the file to be indexed by Time Machine
[self setTimeMachineExclude:NO]; [self setTimeMachineExclude:NO];
tr_torrentRemove(self.fHandle, trashFiles, trashDataFile); tr_torrentRemove(self.fHandle, trashFiles, trashDataFile, nullptr);
} }
- (void)changeDownloadFolderBeforeUsing:(NSString*)folder determinationType:(TorrentDeterminationType)determinationType - (void)changeDownloadFolderBeforeUsing:(NSString*)folder determinationType:(TorrentDeterminationType)determinationType

View File

@@ -133,7 +133,7 @@ TEST_P(IncompleteDirTest, incompleteDir)
} }
// cleanup // cleanup
tr_torrentRemove(tor, true, tr_sys_path_remove); tr_torrentRemove(tor, true, nullptr, nullptr);
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
@@ -187,7 +187,7 @@ TEST_F(MoveTest, setLocation)
} }
// cleanup // cleanup
tr_torrentRemove(tor, true, tr_sys_path_remove); tr_torrentRemove(tor, true, nullptr, nullptr);
} }
} // namespace test } // namespace test

View File

@@ -35,7 +35,7 @@ class RenameTest : public SessionTest
protected: protected:
void torrentRemoveAndWait(tr_torrent* tor, size_t expected_torrent_count) void torrentRemoveAndWait(tr_torrent* tor, size_t expected_torrent_count)
{ {
tr_torrentRemove(tor, false, nullptr); tr_torrentRemove(tor, false, nullptr, nullptr);
auto const test = [this, expected_torrent_count]() auto const test = [this, expected_torrent_count]()
{ {
return std::size(session_->torrents()) == expected_torrent_count; return std::size(session_->torrents()) == expected_torrent_count;

View File

@@ -185,7 +185,7 @@ TEST_F(RpcTest, sessionGet)
// cleanup // cleanup
tr_variantClear(&response); tr_variantClear(&response);
tr_torrentRemove(tor, false, nullptr); tr_torrentRemove(tor, false, nullptr, nullptr);
} }
} // namespace test } // namespace test