* Properly use d.set_directory_base when

* Added get_{up,down}_{rate,total}.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1023 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2007-12-30 04:43:05 +00:00
parent 7b053b969e
commit ce64ea89b1
8 changed files with 47 additions and 47 deletions
+6
View File
@@ -44,6 +44,7 @@
#include <torrent/tracker.h>
#include <torrent/tracker_list.h>
#include <torrent/torrent.h>
#include <torrent/rate.h>
#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));
+1 -1
View File
@@ -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));
+2 -3
View File
@@ -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(&not_correct_format)), d.end());
+3 -3
View File
@@ -459,17 +459,17 @@ path_expand(std::vector<std::string>* paths, const std::string& pattern) {
for (std::vector<utils::Directory>::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
+1 -1
View File
@@ -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;
+9 -4
View File
@@ -100,16 +100,21 @@ parse_options(Control* c, int argc, char** argv) {
void
load_session_torrents(Control* c) {
// Load session torrents.
std::vector<std::string> 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<std::string>::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<core::DownloadFactory>), f));
f->load(*first);
f->load(entries.path() + first->d_name);
f->commit();
}
}
+15 -27
View File
@@ -38,9 +38,9 @@
#include <algorithm>
#include <functional>
#include <stdexcept>
#include <dirent.h>
#include <rak/path.h>
#include <torrent/exceptions.h>
#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<std::string>
Directory::make_list() {
std::vector<std::string> l;
l.reserve(size());
for (iterator itr = begin(); itr != end(); ++itr)
l.push_back(m_path + itr->d_name);
return l;
}
}
+10 -8
View File
@@ -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<std::string> make_list();
bool update(int flags);
private:
std::string m_path;