Changeset 1023 for trunk/rtorrent/src/utils/directory.cc
- Timestamp:
- 12/29/07 23:43:05 (4 years ago)
- Files:
-
- 1 modified
-
trunk/rtorrent/src/utils/directory.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/rtorrent/src/utils/directory.cc
r1022 r1023 39 39 #include <algorithm> 40 40 #include <functional> 41 #include <stdexcept>42 41 #include <dirent.h> 43 42 #include <rak/path.h> 43 #include <torrent/exceptions.h> 44 44 45 45 #include "directory.h" … … 61 61 // Update should take various flags and sort functors. 62 62 bool 63 Directory::update( bool hideDot) {63 Directory::update(int flags) { 64 64 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."); 66 66 67 67 DIR* d = opendir(rak::path_expand(m_path).c_str()); … … 70 70 return false; 71 71 72 struct dirent* ent ;72 struct dirent* entry; 73 73 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; 78 77 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()); 81 79 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); 87 84 } 88 85 89 86 closedir(d); 90 std::sort(begin(), end()); 87 88 if (flags & update_sort) 89 std::sort(begin(), end()); 91 90 92 91 return true; 93 92 } 94 93 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;104 94 } 105 106 }
