* Refactoring utils::Directory.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1022 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2007-12-23 19:12:23 +00:00
parent ccb3713a57
commit 7b053b969e
11 changed files with 126 additions and 62 deletions
+18 -7
View File
@@ -46,6 +46,7 @@
namespace utils {
// Keep this?
bool
Directory::is_valid() const {
if (m_path.empty())
@@ -57,6 +58,7 @@ Directory::is_valid() const {
return d;
}
// Update should take various flags and sort functors.
bool
Directory::update(bool hideDot) {
if (m_path.empty())
@@ -69,25 +71,34 @@ Directory::update(bool hideDot) {
struct dirent* ent;
// 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);
if (!de.empty() && (!hideDot || de[0] != '.'))
Base::push_back(ent->d_name);
if (!de.empty() && (!hideDot || de[0] != '.')) {
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;
}
}
closedir(d);
Base::sort(std::less<std::string>());
std::sort(begin(), end());
return true;
}
Directory::Base
std::vector<std::string>
Directory::make_list() {
Base l;
std::vector<std::string> l;
l.reserve(size());
for (Base::iterator itr = begin(); itr != end(); ++itr)
l.push_back(m_path + *itr);
for (iterator itr = begin(); itr != end(); ++itr)
l.push_back(m_path + itr->d_name);
return l;
}