From 5aa45bbaf4d9aa911b726f7430b3bd9eee0285fc Mon Sep 17 00:00:00 2001 From: rakshasa Date: Thu, 8 Oct 2026 12:15:22 +0200 Subject: [PATCH] Removed old LOG_TORRENT_* categories and replaced with LOG_TORRENT_{DEBUG,EVENTS}. --- src/command_download.cc | 8 ++--- src/command_events.cc | 8 ++--- src/command_groups.cc | 5 +-- src/core/download_list.cc | 64 +++++++++++++++++++-------------- src/core/manager.cc | 3 +- src/ui/element_download_list.cc | 3 +- 6 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/command_download.cc b/src/command_download.cc index d76651ea..7aa265af 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -107,7 +107,7 @@ apply_d_change_link(core::Download* download, const torrent::Object::list_type& switch (changeType) { case 0: if (symlink(target.c_str(), link.c_str()) == -1) - lt_log_print(torrent::LOG_TORRENT_WARN, "create_link failed: %s", std::strerror(errno)); + lt_log_print(torrent::LOG_TORRENT_DEBUG, "create_link failed: %s", std::strerror(errno)); break; @@ -117,7 +117,7 @@ apply_d_change_link(core::Download* download, const torrent::Object::list_type& errno = 0; if (!fileStat.update_link(link) || !fileStat.is_link() || unlink(link.c_str()) == -1) - lt_log_print(torrent::LOG_TORRENT_WARN, "delete_link failed: %s", std::strerror(errno)); + lt_log_print(torrent::LOG_TORRENT_DEBUG, "delete_link failed: %s", std::strerror(errno)); break; } @@ -135,7 +135,7 @@ apply_d_delete_tied(core::Download* download) { if (tie.empty()) return torrent::Object(); - if (::unlink(expand_path(tie).c_str()) == -1) + if (unlink(expand_path(tie).c_str()) == -1) control->core()->push_log_std("Could not unlink tied file: " + std::string(std::strerror(errno))); rpc::call_command("d.tied_to_file.set", std::string(), rpc::make_target(download)); @@ -293,7 +293,7 @@ apply_d_add_peer(core::Download* download, const std::string& arg) { // Currently discarding SOCK_STREAM. torrent::this_thread::resolver()->resolve_preferred(callback_id, host, AF_UNSPEC, AF_INET, [download, port](torrent::c_sa_shared_ptr sa, int err) { if (sa == nullptr) { - lt_log_print(torrent::LOG_TORRENT_WARN, "could not resolve hostname for added peer: %s", gai_strerror(err)); + lt_log_print(torrent::LOG_TORRENT_DEBUG, "could not resolve hostname for added peer: %s", gai_strerror(err)); return; } diff --git a/src/command_events.cc b/src/command_events.cc index 74203f77..65bab28a 100644 --- a/src/command_events.cc +++ b/src/command_events.cc @@ -169,7 +169,7 @@ void apply_try_import(const std::string& path) { if (!rpc::parse_command_file(pa torrent::Object apply_close_low_diskspace(int64_t arg, uint32_t skip_priority) { - bool closed = false; + int closed{}; torrent::FileList::cache_list cache; @@ -186,11 +186,11 @@ apply_close_low_diskspace(int64_t arg, uint32_t skip_priority) { download->set_hash_failed(true); download->set_message(std::string("Low diskspace.")); - closed = true; + closed++; } - if (closed) - lt_log_print(torrent::LOG_TORRENT_ERROR, "Closed torrents due to low diskspace."); + if (closed != 0) + lt_log_print(torrent::LOG_TORRENT_EVENTS, "closed torrents due to low diskspace : count:%i", closed); return torrent::Object(); } diff --git a/src/command_groups.cc b/src/command_groups.cc index 69bf326d..119a7df7 100644 --- a/src/command_groups.cc +++ b/src/command_groups.cc @@ -20,9 +20,6 @@ // For cg_d_group. #include "core/download.h" -#define LT_LOG_SUBSYSTEM(log_fmt, ...) \ - lt_log_print_subsystem(torrent::LOG_TORRENT_INFO, "choke_queue", log_fmt, __VA_ARGS__); - // A hack to allow testing of the new choke_group API without the // working parts present. #define USE_CHOKE_GROUP 0 @@ -207,7 +204,7 @@ apply_cg_index_of(const std::string& arg) { torrent::Object apply_cg_all_update_balance(bool is_up) { - LT_LOG_SUBSYSTEM("apply update balance: hack is_up:%i", (int)is_up); + lt_log_print(torrent::LOG_TORRENT_DEBUG, "choke_queue : applying update balance : is_up:%i", (int)is_up); for (const auto& itr : cg_list_hack) { if (is_up) diff --git a/src/core/download_list.cc b/src/core/download_list.cc index 6fd24664..8079f7b4 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -29,7 +29,12 @@ #include "session/session_manager.h" #include "ui/root.h" -#define DL_TRIGGER_EVENT(download, event_name) \ +#define LT_LOG_DOWNLOAD_DEBUG(log_fmt, ...) \ + lt_log_print_hash_only(torrent::LOG_TORRENT_DEBUG, download->info()->hash(), "download_list : " log_fmt, __VA_ARGS__); +#define LT_LOG_DOWNLOAD_EVENTS(log_fmt, ...) \ + lt_log_print_info(torrent::LOG_TORRENT_EVENTS, download->info(), "download_list", log_fmt, __VA_ARGS__); + +#define DL_TRIGGER_EVENT(download, event_name) \ rpc::commands.call_catch(event_name, rpc::make_target(download), torrent::Object(), "Event '" event_name "' failed: "); namespace core { @@ -109,7 +114,7 @@ DownloadList::create(torrent::Object* obj, uint32_t tracker_key, bool printLog) } catch (torrent::local_error& e) { if (printLog) - lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not create download: %s", e.what()); + lt_log_print(torrent::LOG_TORRENT_EVENTS, "download_list : could not create download : %s", e.what()); delete obj; @@ -135,7 +140,7 @@ DownloadList::create(std::istream* str, uint32_t tracker_key, bool printLog) { delete object; if (printLog) - lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not create download, the input is not a valid torrent."); + lt_log_print(torrent::LOG_TORRENT_EVENTS, "download_list : could not create download : invalid or incomplete bencode data"); return NULL; } @@ -146,7 +151,7 @@ DownloadList::create(std::istream* str, uint32_t tracker_key, bool printLog) { delete object; if (printLog) - lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not create download: %s", e.what()); + lt_log_print(torrent::LOG_TORRENT_EVENTS, "download_list : could not create download : %s", e.what()); return NULL; } @@ -160,7 +165,7 @@ DownloadList::iterator DownloadList::insert(Download* download) { iterator itr = base_type::insert(end(), std::shared_ptr(download)); - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Inserting download."); + LT_LOG_DOWNLOAD_DEBUG("inserting download", 0); try { (*itr)->data()->slot_initial_hash() = std::bind(&DownloadList::hash_done, this, download); @@ -200,7 +205,7 @@ DownloadList::erase(iterator itr) { (*itr)->set_erasing(); - lt_log_print_info(torrent::LOG_TORRENT_INFO, (*itr)->info(), "download_list", "Erasing download."); + lt_log_print_hash_only(torrent::LOG_TORRENT_DEBUG, (*itr)->info()->hash(), "download_list : removing download"); // Makes sure close doesn't restart hashing of this download. (*itr)->set_hash_failed(true); @@ -228,7 +233,7 @@ DownloadList::open(Download* download) { return true; } catch (torrent::local_error& e) { - lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not open download: %s", e.what()); + lt_log_print(torrent::LOG_TORRENT_EVENTS, "download_list : could not open download : %s", e.what()); return false; } } @@ -237,7 +242,7 @@ void DownloadList::open_throw(Download* download) { check_contains(download); - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Opening download."); + lt_log_print_hash_only(torrent::LOG_TORRENT_DEBUG, download->info()->hash(), "download_list : opening download"); if (download->download()->info()->is_open()) return; @@ -248,6 +253,7 @@ DownloadList::open_throw(Download* download) { openFlags |= torrent::Download::open_enable_fallocate; download->download()->open(openFlags); + DL_TRIGGER_EVENT(download, "event.download.opened"); } @@ -257,7 +263,7 @@ DownloadList::close(Download* download) { close_throw(download); } catch (torrent::local_error& e) { - lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not close download: %s", e.what()); + lt_log_print(torrent::LOG_TORRENT_EVENTS, "download_list : could not close download : %s", e.what()); } } @@ -265,7 +271,7 @@ DownloadList::close(Download* download) { // need the files closed and will keep using the download. void DownloadList::close_files(Download* download) { - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Closing download files."); + lt_log_print_hash_only(torrent::LOG_TORRENT_DEBUG, download->info()->hash(), "download_list : closing download files"); if (download->download()->info()->is_active()) { download->download()->stop(torrent::Download::stop_skip_tracker); @@ -280,7 +286,7 @@ DownloadList::close_files(Download* download) { void DownloadList::close_directly(Download* download) { - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Closing download directly."); + lt_log_print_hash_only(torrent::LOG_TORRENT_DEBUG, download->info()->hash(), "download_list : closing download directly"); auto lifetime = download->lifetime(); bool was_active = download->download()->info()->is_active(); @@ -327,7 +333,8 @@ DownloadList::update_paused_state(Download* download) { void DownloadList::close_quick(Download* download) { - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Closing download quickly."); + lt_log_print_hash_only(torrent::LOG_TORRENT_DEBUG, download->info()->hash(), "download_list : closing download quickly."); + close(download); // Make sure we cancel any tracker requests. This should rather be @@ -341,7 +348,7 @@ void DownloadList::close_throw(Download* download) { check_contains(download); - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Closing download with throw."); + LT_LOG_DOWNLOAD_DEBUG("closing download with throw", 0); // When pause gets called it will clear the initial hash check state // and set hash failed. This should ensure hashing doesn't restart @@ -383,7 +390,7 @@ void DownloadList::resume(Download* download, int flags) { check_contains(download); - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Resuming download: flags:%0x.", flags); + LT_LOG_DOWNLOAD_DEBUG("resuming download : flags:%0x.", flags); try { @@ -472,7 +479,7 @@ DownloadList::resume(Download* download, int flags) { DL_TRIGGER_EVENT(download, "event.download.resumed"); } catch (torrent::local_error& e) { - lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not resume download: %s", e.what()); + LT_LOG_DOWNLOAD_EVENTS("could not resume download : %s", e.what()); } } @@ -480,7 +487,7 @@ void DownloadList::pause(Download* download, int flags) { check_contains(download); - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Pausing download: flags:%0x.", flags); + LT_LOG_DOWNLOAD_DEBUG("pausing download : flags:%0x.", flags); auto lifetime = download->lifetime(); @@ -523,7 +530,7 @@ DownloadList::pause(Download* download, int flags) { //control->core()->download_store()->save(download); } catch (torrent::local_error& e) { - lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not pause download: %s", e.what()); + LT_LOG_DOWNLOAD_EVENTS("could not pause download : %s", e.what()); } } @@ -531,7 +538,7 @@ void DownloadList::check_hash(Download* download) { check_contains(download); - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Checking hash."); + LT_LOG_DOWNLOAD_DEBUG("checking hash", 0); try { if (rpc::call_command_value("d.hashing", rpc::make_target(download)) != Download::variable_hashing_stopped) @@ -540,7 +547,7 @@ DownloadList::check_hash(Download* download) { hash_queue(download, Download::variable_hashing_rehash); } catch (torrent::local_error& e) { - lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not check hash: %s", e.what()); + LT_LOG_DOWNLOAD_EVENTS("could not check hash : %s", e.what()); } } @@ -548,7 +555,7 @@ void DownloadList::hash_done(Download* download) { check_contains(download); - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Hash done."); + LT_LOG_DOWNLOAD_DEBUG("hash done", 0); if (download->is_hash_checking() || download->is_active()) throw torrent::internal_error("DownloadList::hash_done(...) download in invalid state."); @@ -613,7 +620,8 @@ DownloadList::hash_done(Download* download) { confirm_finished(download); } else { download->set_message("Hash check on download completion found bad chunks."); - lt_log_print(torrent::LOG_TORRENT_ERROR, "Hash check on download completion found bad chunks."); + LT_LOG_DOWNLOAD_EVENTS("hash check on download completion found bad chunks", 0); + DL_TRIGGER_EVENT(download, "event.download.hash_final_failed"); } @@ -634,7 +642,7 @@ void DownloadList::hash_queue(Download* download, int type) { check_contains(download); - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Hash queue."); + LT_LOG_DOWNLOAD_DEBUG("hash queue : type:%d", type); if (rpc::call_command_value("d.hashing", rpc::make_target(download)) != Download::variable_hashing_stopped) throw torrent::internal_error("DownloadList::hash_queue(...) hashing already queued."); @@ -678,7 +686,7 @@ void DownloadList::received_finished(Download* download) { check_contains(download); - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Received finished."); + LT_LOG_DOWNLOAD_DEBUG("received finished", 0); if (rpc::call_command_value("pieces.hash.on_completion")) // Set some 'checking_finished_thingie' variable to make hash_done @@ -693,7 +701,7 @@ void DownloadList::confirm_finished(Download* download) { check_contains(download); - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Confirming finished."); + LT_LOG_DOWNLOAD_DEBUG("confirming finished", 0); if (download->download()->info()->is_meta_download()) return process_meta_download(download); @@ -768,7 +776,7 @@ DownloadList::confirm_finished(Download* download) { void DownloadList::process_meta_download(Download* download) { - lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Processing meta download."); + LT_LOG_DOWNLOAD_DEBUG("processing meta download", 0); rpc::call_command("d.stop", torrent::Object(), rpc::make_target(download)); rpc::call_command("d.close", torrent::Object(), rpc::make_target(download)); @@ -778,7 +786,7 @@ DownloadList::process_meta_download(Download* download) { std::fstream file(metafile.c_str(), std::ios::in | std::ios::binary); if (!file.is_open()) { - lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not read download metadata."); + LT_LOG_DOWNLOAD_EVENTS("could not read download metadata : %s", metafile.c_str()); return; } @@ -786,7 +794,7 @@ DownloadList::process_meta_download(Download* download) { file >> bencode->insert_key("info", torrent::Object()); if (file.fail()) { - lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not create download, the input is not a valid torrent."); + LT_LOG_DOWNLOAD_EVENTS("could not create download, the input is not a valid torrent : %s", metafile.c_str()); return; } @@ -794,8 +802,10 @@ DownloadList::process_meta_download(Download* download) { // Steal the keys we still need. The old download has no use for them. bencode->insert_key("rtorrent_meta_download", torrent::Object()).swap(download->bencode()->get_key("rtorrent_meta_download")); + if (download->bencode()->has_key("announce")) bencode->insert_key("announce", torrent::Object()).swap(download->bencode()->get_key("announce")); + if (download->bencode()->has_key("announce-list")) bencode->insert_key("announce-list", torrent::Object()).swap(download->bencode()->get_key("announce-list")); diff --git a/src/core/manager.cc b/src/core/manager.cc index 1fcb55c1..7c7387b7 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -440,7 +440,8 @@ Manager::receive_hashing_changed() { } else { (*itr)->set_hash_failed(true); (*itr)->set_message("Hashing failed: " + std::string(e.what())); - lt_log_print(torrent::LOG_TORRENT_ERROR, "Hashing failed: %s", e.what()); + + lt_log_print_hash_only(torrent::LOG_TORRENT_EVENTS, (*itr)->info()->hash(), "hashing failed : %s", e.what()); } } } diff --git a/src/ui/element_download_list.cc b/src/ui/element_download_list.cc index 9f651fd6..57f9a2ea 100644 --- a/src/ui/element_download_list.cc +++ b/src/ui/element_download_list.cc @@ -197,8 +197,9 @@ ElementDownloadList::receive_cycle_throttle() { return; core::Download* download = m_view->focus()->get(); + if (download->is_active()) { - lt_log_print(torrent::LOG_TORRENT_WARN, "Cannot change throttle on active download."); + lt_log_print_hash_only(torrent::LOG_TORRENT_DEBUG, download->info()->hash(), "cannot change throttle on active download"); return; }