update listdir example to use path

master
Daniel Kolesa 2018-04-16 03:20:23 +02:00
parent 0d0655b09e
commit 755e0f3934
3 changed files with 8 additions and 8 deletions

View File

@ -28,7 +28,7 @@ namespace fs = ostd::filesystem;
/* ugly, but do not explicitly compile */ /* ugly, but do not explicitly compile */
#include "src/io.cc" #include "src/io.cc"
#include "src/process.cc" #include "src/process.cc"
#include "srC/path.cc" #include "src/path.cc"
#include "src/filesystem.cc" #include "src/filesystem.cc"
#include "src/thread_pool.cc" #include "src/thread_pool.cc"
#include "src/channel.cc" #include "src/channel.cc"

View File

@ -4,21 +4,20 @@
*/ */
#include <ostd/io.hh> #include <ostd/io.hh>
#include <ostd/filesystem.hh> #include <ostd/path.hh>
#include <ostd/range.hh> #include <ostd/range.hh>
using namespace ostd; using namespace ostd;
inline void list_dirs(filesystem::path const &path, int off = 0) { inline void list_dirs(path const &path, int off = 0) {
filesystem::directory_iterator ds{path}; fs::directory_range ds{path};
for (auto &v: ds) { for (auto &v: ds) {
auto p = filesystem::path{v}; if (!fs::is_directory(v.path())) {
if (!filesystem::is_directory(p)) {
continue; continue;
} }
for_each(range(off), [](int) { write(' '); }); for_each(range(off), [](int) { write(' '); });
writeln(p.filename()); writeln(v.path().name());
list_dirs(p, off + 1); list_dirs(v.path(), off + 1);
} }
} }

View File

@ -150,6 +150,7 @@ OSTD_EXPORT void rdir_range_impl::read_next() {
if (p_handles.empty()) { if (p_handles.empty()) {
return; return;
} }
/* can't reuse info from dirent because we need to expand symlinks */
if (is_directory(p_current.path())) { if (is_directory(p_current.path())) {
/* directory, recurse into it and if it contains stuff, return */ /* directory, recurse into it and if it contains stuff, return */
DIR *nd = opendir(p_current.path().string().data()); DIR *nd = opendir(p_current.path().string().data());