Changeset 1023

Show
Ignore:
Timestamp:
12/29/07 23:43:05 (4 years ago)
Author:
rakshasa
Message:

* Properly use d.set_directory_base when

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

Location:
trunk/rtorrent/src
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/rtorrent/src/command_network.cc

    r1022 r1023  
    4545#include <torrent/tracker_list.h> 
    4646#include <torrent/torrent.h> 
     47#include <torrent/rate.h> 
    4748 
    4849#include "core/dht_manager.h" 
     
    320321  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)); 
    321322 
     323  ADD_COMMAND_VOID("get_up_rate",               rak::make_mem_fun(torrent::up_rate(), &torrent::Rate::rate)); 
     324  ADD_COMMAND_VOID("get_up_total",              rak::make_mem_fun(torrent::up_rate(), &torrent::Rate::total)); 
     325  ADD_COMMAND_VOID("get_down_rate",             rak::make_mem_fun(torrent::down_rate(), &torrent::Rate::rate)); 
     326  ADD_COMMAND_VOID("get_down_total",            rak::make_mem_fun(torrent::down_rate(), &torrent::Rate::total)); 
     327 
    322328  ADD_VARIABLE_VALUE("tracker_numwant", -1); 
    323329 
  • trunk/rtorrent/src/core/download_factory.cc

    r1017 r1023  
    223223    rpc::call_command("d.set_directory", m_variables["directory"], rpc::make_target(download)); 
    224224  else 
    225     rpc::call_command("d.set_directory", rtorrent->get_key("directory"), rpc::make_target(download)); 
     225    rpc::call_command("d.set_directory_base", rtorrent->get_key("directory"), rpc::make_target(download)); 
    226226 
    227227  if (!m_session && m_variables["tied_to_file"].as_value()) 
  • trunk/rtorrent/src/core/download_store.cc

    r1022 r1023  
    158158    return utils::Directory(); 
    159159 
    160   utils::Directory d; 
    161   d.set_path(m_path); 
     160  utils::Directory d(m_path); 
    162161 
    163   if (!d.update()) 
     162  if (!d.update(utils::Directory::update_hide_dot)) 
    164163    throw torrent::storage_error("core::DownloadStore::update() could not open directory \"" + m_path + "\""); 
    165164 
  • trunk/rtorrent/src/core/manager.cc

    r1022 r1023  
    460460      // Only include filenames starting with '.' if the pattern 
    461461      // starts with the same. 
    462       itr->update(r.pattern()[0] != '.'); 
     462      itr->update((r.pattern()[0] != '.') ? utils::Directory::update_hide_dot : 0); 
    463463      itr->erase(std::remove_if(itr->begin(), itr->end(), rak::on(rak::mem_ref(&utils::directory_entry::d_name), std::not1(r))), itr->end()); 
    464464 
    465       std::transform(itr->begin(), itr->end(), std::back_inserter(nextCache), rak::bind1st(std::ptr_fun(&path_expand_transform), itr->get_path() + "/")); 
     465      std::transform(itr->begin(), itr->end(), std::back_inserter(nextCache), rak::bind1st(std::ptr_fun(&path_expand_transform), itr->path() + "/")); 
    466466    } 
    467467 
     
    470470  } 
    471471 
    472   std::transform(currentCache.begin(), currentCache.end(), std::back_inserter(*paths), std::mem_fun_ref(&utils::Directory::get_path)); 
     472  std::transform(currentCache.begin(), currentCache.end(), std::back_inserter(*paths), std::mem_fun_ref(&utils::Directory::path)); 
    473473} 
    474474 
  • trunk/rtorrent/src/input/path_input.cc

    r1022 r1023  
    8484  utils::Directory dir(dirEnd != 0 ? str().substr(0, dirEnd) : "./"); 
    8585   
    86   if (!dir.update() || dir.empty()) { 
     86  if (!dir.update(utils::Directory::update_sort | utils::Directory::update_hide_dot) || dir.empty()) { 
    8787    mark_dirty(); 
    8888 
  • trunk/rtorrent/src/main.cc

    r1022 r1023  
    101101void 
    102102load_session_torrents(Control* c) { 
    103   // Load session torrents. 
    104   std::vector<std::string> l = c->core()->download_store()->get_formated_entries().make_list(); 
    105  
    106   for (std::vector<std::string>::iterator first = l.begin(), last = l.end(); first != last; ++first) { 
     103  utils::Directory entries = c->core()->download_store()->get_formated_entries(); 
     104 
     105  for (utils::Directory::const_iterator first = entries.begin(), last = entries.end(); first != last; ++first) { 
     106    // We don't really support session torrents that are links. These 
     107    // would be overwritten anyway on exit, and thus not really be 
     108    // useful. 
     109    if (!first->is_file()) 
     110      continue; 
     111 
    107112    core::DownloadFactory* f = new core::DownloadFactory(c->core()); 
    108113 
     
    110115    f->set_session(true); 
    111116    f->slot_finished(sigc::bind(sigc::ptr_fun(&rak::call_delete_func<core::DownloadFactory>), f)); 
    112     f->load(*first); 
     117    f->load(entries.path() + first->d_name); 
    113118    f->commit(); 
    114119  } 
  • trunk/rtorrent/src/utils/directory.cc

    r1022 r1023  
    3939#include <algorithm> 
    4040#include <functional> 
    41 #include <stdexcept> 
    4241#include <dirent.h> 
    4342#include <rak/path.h> 
     43#include <torrent/exceptions.h> 
    4444 
    4545#include "directory.h" 
     
    6161// Update should take various flags and sort functors. 
    6262bool 
    63 Directory::update(bool hideDot) { 
     63Directory::update(int flags) { 
    6464  if (m_path.empty()) 
    65     throw std::logic_error("Directory::update() tried to open an empty path"); 
     65    throw torrent::input_error("Directory::update() tried to open an empty path."); 
    6666 
    6767  DIR* d = opendir(rak::path_expand(m_path).c_str()); 
     
    7070    return false; 
    7171 
    72   struct dirent* ent; 
     72  struct dirent* entry; 
    7373 
    74   // Err... let us use getdirentries here instead. 
    75   while ((ent = readdir(d)) != NULL) { 
    76     // Don't construct it here, check the const char. 
    77     std::string de(ent->d_name); 
     74  while ((entry = readdir(d)) != NULL) { 
     75    if ((flags & update_hide_dot) && entry->d_name[0] == '.') 
     76      continue; 
    7877 
    79     if (!de.empty() && (!hideDot || de[0] != '.')) { 
    80       iterator itr = base_type::insert(end(), value_type()); 
     78    iterator itr = base_type::insert(end(), value_type()); 
    8179 
    82       itr->d_fileno = ent->d_fileno; 
    83       itr->d_reclen = ent->d_reclen; 
    84       itr->d_type   = ent->d_type; 
    85       itr->d_name   = de; 
    86     } 
     80    itr->d_fileno = entry->d_fileno; 
     81    itr->d_reclen = entry->d_reclen; 
     82    itr->d_type   = entry->d_type; 
     83    itr->d_name   = std::string(entry->d_name, entry->d_name + entry->d_namlen); 
    8784  } 
    8885 
    8986  closedir(d); 
    90   std::sort(begin(), end()); 
     87 
     88  if (flags & update_sort) 
     89    std::sort(begin(), end()); 
    9190 
    9291  return true; 
    9392} 
    9493 
    95 std::vector<std::string> 
    96 Directory::make_list() { 
    97   std::vector<std::string> l; 
    98   l.reserve(size()); 
    99  
    100   for (iterator itr = begin(); itr != end(); ++itr) 
    101     l.push_back(m_path + itr->d_name); 
    102  
    103   return l; 
    10494} 
    105  
    106 } 
  • trunk/rtorrent/src/utils/directory.h

    r1022 r1023  
    4444 
    4545struct directory_entry { 
     46  // Fix. 
     47  bool is_file() const { return true; } 
     48 
    4649  // The name and types should match POSIX. 
    4750  uint32_t            d_fileno; 
     
    7275  using base_type::erase; 
    7376 
     77  static const uint32_t buffer_size = 64 * 1024; 
     78 
     79  static const int update_sort     = 0x1; 
     80  static const int update_hide_dot = 0x2; 
     81 
    7482  Directory() {} 
    7583  Directory(const std::string& path) : m_path(path) {} 
     
    7785  bool                is_valid() const; 
    7886 
    79   bool                update(bool hideDot = true); 
    80  
    81   // Ergh... 
    82   const std::string&  get_path() { return m_path; } 
     87  const std::string&  path()                            { return m_path; } 
    8388  void                set_path(const std::string& path) { m_path = path; } 
    8489 
    85   // Make a list with full path names. 
    86   // 
    87   // Fix the uses of this, real bad stuff. 
    88   std::vector<std::string> make_list(); 
     90  bool                update(int flags); 
    8991 
    9092private: