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}.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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 }