diff --git a/src/command_network.cc b/src/command_network.cc index c932dbab..8e2f2041 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -44,6 +44,7 @@ #include #include #include +#include #include "core/dht_manager.h" #include "core/download.h" @@ -319,6 +320,11 @@ initialize_command_network() { ADD_COMMAND_VALUE_TRI_KB("download_rate", rak::make_mem_fun(control->ui(), &ui::Root::set_down_throttle_i64), rak::ptr_fun(&torrent::down_throttle)); ADD_COMMAND_VALUE_TRI_KB("upload_rate", rak::make_mem_fun(control->ui(), &ui::Root::set_up_throttle_i64), rak::ptr_fun(&torrent::up_throttle)); + ADD_COMMAND_VOID("get_up_rate", rak::make_mem_fun(torrent::up_rate(), &torrent::Rate::rate)); + ADD_COMMAND_VOID("get_up_total", rak::make_mem_fun(torrent::up_rate(), &torrent::Rate::total)); + ADD_COMMAND_VOID("get_down_rate", rak::make_mem_fun(torrent::down_rate(), &torrent::Rate::rate)); + ADD_COMMAND_VOID("get_down_total", rak::make_mem_fun(torrent::down_rate(), &torrent::Rate::total)); + ADD_VARIABLE_VALUE("tracker_numwant", -1); ADD_COMMAND_LIST("encryption", rak::ptr_fn(&apply_encryption)); diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index 2835db8d..90e1e8c7 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -222,7 +222,7 @@ DownloadFactory::receive_success() { if (!rtorrent->has_key_string("directory")) rpc::call_command("d.set_directory", m_variables["directory"], rpc::make_target(download)); else - rpc::call_command("d.set_directory", rtorrent->get_key("directory"), rpc::make_target(download)); + rpc::call_command("d.set_directory_base", rtorrent->get_key("directory"), rpc::make_target(download)); if (!m_session && m_variables["tied_to_file"].as_value()) rpc::call_command("d.set_tied_to_file", m_uri, rpc::make_target(download)); diff --git a/src/core/download_store.cc b/src/core/download_store.cc index d1b366f4..9e51b1b1 100644 --- a/src/core/download_store.cc +++ b/src/core/download_store.cc @@ -157,10 +157,9 @@ DownloadStore::get_formated_entries() { if (!is_enabled()) return utils::Directory(); - utils::Directory d; - d.set_path(m_path); + utils::Directory d(m_path); - if (!d.update()) + if (!d.update(utils::Directory::update_hide_dot)) throw torrent::storage_error("core::DownloadStore::update() could not open directory \"" + m_path + "\""); d.erase(std::remove_if(d.begin(), d.end(), std::ptr_fun(¬_correct_format)), d.end()); diff --git a/src/core/manager.cc b/src/core/manager.cc index 1e6d60dc..7d6ff4c8 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -459,17 +459,17 @@ path_expand(std::vector* paths, const std::string& pattern) { for (std::vector::iterator itr = currentCache.begin(); itr != currentCache.end(); ++itr) { // Only include filenames starting with '.' if the pattern // starts with the same. - itr->update(r.pattern()[0] != '.'); + itr->update((r.pattern()[0] != '.') ? utils::Directory::update_hide_dot : 0); itr->erase(std::remove_if(itr->begin(), itr->end(), rak::on(rak::mem_ref(&utils::directory_entry::d_name), std::not1(r))), itr->end()); - std::transform(itr->begin(), itr->end(), std::back_inserter(nextCache), rak::bind1st(std::ptr_fun(&path_expand_transform), itr->get_path() + "/")); + std::transform(itr->begin(), itr->end(), std::back_inserter(nextCache), rak::bind1st(std::ptr_fun(&path_expand_transform), itr->path() + "/")); } currentCache.clear(); currentCache.swap(nextCache); } - std::transform(currentCache.begin(), currentCache.end(), std::back_inserter(*paths), std::mem_fun_ref(&utils::Directory::get_path)); + std::transform(currentCache.begin(), currentCache.end(), std::back_inserter(*paths), std::mem_fun_ref(&utils::Directory::path)); } bool diff --git a/src/input/path_input.cc b/src/input/path_input.cc index 1422bb7e..f20d2e72 100644 --- a/src/input/path_input.cc +++ b/src/input/path_input.cc @@ -83,7 +83,7 @@ PathInput::receive_do_complete() { utils::Directory dir(dirEnd != 0 ? str().substr(0, dirEnd) : "./"); - if (!dir.update() || dir.empty()) { + if (!dir.update(utils::Directory::update_sort | utils::Directory::update_hide_dot) || dir.empty()) { mark_dirty(); return; diff --git a/src/main.cc b/src/main.cc index 5acfce32..78079d93 100644 --- a/src/main.cc +++ b/src/main.cc @@ -100,16 +100,21 @@ parse_options(Control* c, int argc, char** argv) { void load_session_torrents(Control* c) { - // Load session torrents. - std::vector l = c->core()->download_store()->get_formated_entries().make_list(); + utils::Directory entries = c->core()->download_store()->get_formated_entries(); + + for (utils::Directory::const_iterator first = entries.begin(), last = entries.end(); first != last; ++first) { + // We don't really support session torrents that are links. These + // would be overwritten anyway on exit, and thus not really be + // useful. + if (!first->is_file()) + continue; - for (std::vector::iterator first = l.begin(), last = l.end(); first != last; ++first) { core::DownloadFactory* f = new core::DownloadFactory(c->core()); // Replace with session torrent flag. f->set_session(true); f->slot_finished(sigc::bind(sigc::ptr_fun(&rak::call_delete_func), f)); - f->load(*first); + f->load(entries.path() + first->d_name); f->commit(); } } diff --git a/src/utils/directory.cc b/src/utils/directory.cc index fc53a318..30c82697 100644 --- a/src/utils/directory.cc +++ b/src/utils/directory.cc @@ -38,9 +38,9 @@ #include #include -#include #include #include +#include #include "directory.h" @@ -60,47 +60,35 @@ Directory::is_valid() const { // Update should take various flags and sort functors. bool -Directory::update(bool hideDot) { +Directory::update(int flags) { if (m_path.empty()) - throw std::logic_error("Directory::update() tried to open an empty path"); + throw torrent::input_error("Directory::update() tried to open an empty path."); DIR* d = opendir(rak::path_expand(m_path).c_str()); if (d == NULL) return false; - struct dirent* ent; + struct dirent* entry; - // Err... let us use getdirentries here instead. - while ((ent = readdir(d)) != NULL) { - // Don't construct it here, check the const char. - std::string de(ent->d_name); + while ((entry = readdir(d)) != NULL) { + if ((flags & update_hide_dot) && entry->d_name[0] == '.') + continue; - if (!de.empty() && (!hideDot || de[0] != '.')) { - iterator itr = base_type::insert(end(), value_type()); + iterator itr = base_type::insert(end(), value_type()); - itr->d_fileno = ent->d_fileno; - itr->d_reclen = ent->d_reclen; - itr->d_type = ent->d_type; - itr->d_name = de; - } + itr->d_fileno = entry->d_fileno; + itr->d_reclen = entry->d_reclen; + itr->d_type = entry->d_type; + itr->d_name = std::string(entry->d_name, entry->d_name + entry->d_namlen); } closedir(d); - std::sort(begin(), end()); + + if (flags & update_sort) + std::sort(begin(), end()); return true; } -std::vector -Directory::make_list() { - std::vector l; - l.reserve(size()); - - for (iterator itr = begin(); itr != end(); ++itr) - l.push_back(m_path + itr->d_name); - - return l; -} - } diff --git a/src/utils/directory.h b/src/utils/directory.h index 4a0057a8..44e2303f 100644 --- a/src/utils/directory.h +++ b/src/utils/directory.h @@ -43,6 +43,9 @@ namespace utils { struct directory_entry { + // Fix. + bool is_file() const { return true; } + // The name and types should match POSIX. uint32_t d_fileno; uint16_t d_reclen; @@ -71,21 +74,20 @@ public: using base_type::erase; + static const uint32_t buffer_size = 64 * 1024; + + static const int update_sort = 0x1; + static const int update_hide_dot = 0x2; + Directory() {} Directory(const std::string& path) : m_path(path) {} bool is_valid() const; - bool update(bool hideDot = true); - - // Ergh... - const std::string& get_path() { return m_path; } + const std::string& path() { return m_path; } void set_path(const std::string& path) { m_path = path; } - // Make a list with full path names. - // - // Fix the uses of this, real bad stuff. - std::vector make_list(); + bool update(int flags); private: std::string m_path;