* 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
+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;