mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-16 06:54:03 +00:00
Switch uses of dir_t to dir_iter_t
dir_t was a thin wrapper around readdir; switch to the new dir_iter_t API and remove dir_t.
This commit is contained in:
parent
b684f7b076
commit
36fbfef74c
3 changed files with 3 additions and 29 deletions
|
@ -118,12 +118,11 @@ static void autoload_names(std::unordered_set<wcstring> &names, bool get_hidden)
|
|||
|
||||
for (i = 0; i < path_list.size(); i++) {
|
||||
const wcstring &ndir_str = path_list.at(i);
|
||||
dir_t dir(ndir_str);
|
||||
dir_iter_t dir(ndir_str);
|
||||
if (!dir.valid()) continue;
|
||||
|
||||
wcstring name;
|
||||
while (dir.read(name)) {
|
||||
const wchar_t *fn = name.c_str();
|
||||
while (const auto *entry = dir.next()) {
|
||||
const wchar_t *fn = entry->name.c_str();
|
||||
const wchar_t *suffix;
|
||||
if (!get_hidden && fn[0] == L'_') continue;
|
||||
|
||||
|
|
|
@ -328,22 +328,6 @@ const dir_iter_t::entry_t *dir_iter_t::next() {
|
|||
return &entry_;
|
||||
}
|
||||
|
||||
dir_t::dir_t(const wcstring &path) {
|
||||
const cstring tmp = wcs2string(path);
|
||||
this->dir = opendir(tmp.c_str());
|
||||
}
|
||||
|
||||
dir_t::~dir_t() {
|
||||
if (this->dir != nullptr) {
|
||||
closedir(this->dir);
|
||||
this->dir = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool dir_t::valid() const { return this->dir != nullptr; }
|
||||
|
||||
bool dir_t::read(wcstring &name) const { return wreaddir(this->dir, name); }
|
||||
|
||||
int wstat(const wcstring &file_name, struct stat *buf) {
|
||||
const cstring tmp = wcs2string(file_name);
|
||||
return stat(tmp.c_str(), buf);
|
||||
|
|
|
@ -260,15 +260,6 @@ class dir_iter_t : noncopyable_t {
|
|||
entry_t entry_;
|
||||
};
|
||||
|
||||
/// RAII wrapper for DIR*
|
||||
struct dir_t {
|
||||
DIR *dir;
|
||||
bool valid() const;
|
||||
bool read(wcstring &name) const;
|
||||
dir_t(const wcstring &path);
|
||||
~dir_t();
|
||||
};
|
||||
|
||||
#ifndef HASH_FILE_ID
|
||||
#define HASH_FILE_ID 1
|
||||
namespace std {
|
||||
|
|
Loading…
Reference in a new issue