diff --git a/src/command_events.cc b/src/command_events.cc index 92e345ec..a602298a 100644 --- a/src/command_events.cc +++ b/src/command_events.cc @@ -1,39 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - #include "config.h" #include @@ -216,28 +180,27 @@ void apply_import(const std::string& path) { if (!rpc::parse_command_file(pa void apply_try_import(const std::string& path) { if (!rpc::parse_command_file(path)) control->core()->push_log_std("Could not read resource file: " + path); } torrent::Object -apply_close_low_diskspace(int64_t arg, uint32_t skip_prio) { - core::DownloadList* downloadList = control->core()->download_list(); - +apply_close_low_diskspace(int64_t arg, uint32_t skip_priority) { bool closed = false; - core::Manager::DListItr itr = downloadList->begin(); - while ((itr = std::find_if(itr, downloadList->end(), std::mem_fn(&core::Download::is_downloading))) - != downloadList->end()) { - if ((*itr)->priority() < skip_prio && (*itr)->file_list()->free_diskspace() < (uint64_t)arg) { - downloadList->close(*itr); + for (auto download : *control->core()->download_list()) { + if (!download->is_downloading()) + continue; + if (download->priority() >= skip_priority) + continue; + if (download->file_list()->free_diskspace() >= (uint64_t)arg) + continue; - (*itr)->set_hash_failed(true); - (*itr)->set_message(std::string("Low diskspace.")); + control->core()->download_list()->close(download); - closed = true; - } + download->set_hash_failed(true); + download->set_message(std::string("Low diskspace.")); - ++itr; + closed = true; } if (closed) - lt_log_print(torrent::LOG_TORRENT_ERROR, "Closed torrents due to low diskspace."); + lt_log_print(torrent::LOG_TORRENT_ERROR, "Closed torrents due to low diskspace."); return torrent::Object(); } @@ -391,7 +354,7 @@ initialize_command_events() { core::Manager::create_quiet | core::Manager::create_start | core::Manager::create_raw_data)); CMD2_ANY_LIST ("load.raw_start_verbose", std::bind(&apply_load, std::placeholders::_2, core::Manager::create_start | core::Manager::create_raw_data)); - CMD2_ANY_VALUE ("close_low_diskspace", std::bind(&apply_close_low_diskspace, std::placeholders::_2, 99)); + CMD2_ANY_VALUE ("close_low_diskspace", std::bind(&apply_close_low_diskspace, std::placeholders::_2, 99)); CMD2_ANY_VALUE ("close_low_diskspace.normal", std::bind(&apply_close_low_diskspace, std::placeholders::_2, 3)); CMD2_ANY_LIST ("download_list", std::bind(&apply_download_list, std::placeholders::_2)); diff --git a/src/command_local.cc b/src/command_local.cc index 43c717d7..4e91c92f 100644 --- a/src/command_local.cc +++ b/src/command_local.cc @@ -233,7 +233,6 @@ void initialize_command_local() { core::DownloadList* dList = control->core()->download_list(); core::DownloadStore* dStore = control->core()->download_store(); - rpc::LuaEngine* luaEngine = control->lua_engine(); torrent::ChunkManager* chunkManager = torrent::chunk_manager(); torrent::FileManager* fileManager = torrent::file_manager(); @@ -318,8 +317,10 @@ initialize_command_local() { CMD2_ANY_V ("session.save", std::bind(&core::DownloadList::session_save, dList)); #ifdef HAVE_LUA - CMD2_ANY ("lua.execute", std::bind(&rpc::execute_lua, luaEngine, std::placeholders::_1, std::placeholders::_2, 0)); - CMD2_ANY ("lua.execute.str", std::bind(&rpc::execute_lua, luaEngine, std::placeholders::_1, std::placeholders::_2, rpc::LuaEngine::flag_string)); + rpc::LuaEngine* lua_engine = control->lua_engine(); + + CMD2_ANY ("lua.execute", std::bind(&rpc::execute_lua, lua_engine, std::placeholders::_1, std::placeholders::_2, 0)); + CMD2_ANY ("lua.execute.str", std::bind(&rpc::execute_lua, lua_engine, std::placeholders::_1, std::placeholders::_2, rpc::LuaEngine::flag_string)); #endif #define CMD2_EXECUTE(key, flags) \