add io::directory_iterator
This commit is contained in:
@@ -4,9 +4,10 @@
|
||||
#include <filesystem>
|
||||
|
||||
using namespace io;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
std::filesystem::path StdfsDevice::resolve(std::string_view path) {
|
||||
return root / std::filesystem::u8path(path);
|
||||
fs::path StdfsDevice::resolve(std::string_view path) {
|
||||
return root / fs::u8path(path);
|
||||
}
|
||||
|
||||
void StdfsDevice::write(std::string_view path, const void* data, size_t size) {
|
||||
@@ -29,35 +30,58 @@ void StdfsDevice::read(std::string_view path, void* data, size_t size) {
|
||||
|
||||
size_t StdfsDevice::size(std::string_view path) {
|
||||
auto resolved = resolve(path);
|
||||
return std::filesystem::file_size(resolved);
|
||||
return fs::file_size(resolved);
|
||||
}
|
||||
|
||||
bool StdfsDevice::exists(std::string_view path) {
|
||||
auto resolved = resolve(path);
|
||||
return std::filesystem::exists(resolved);
|
||||
return fs::exists(resolved);
|
||||
}
|
||||
|
||||
bool StdfsDevice::isdir(std::string_view path) {
|
||||
auto resolved = resolve(path);
|
||||
return std::filesystem::is_directory(resolved);
|
||||
return fs::is_directory(resolved);
|
||||
}
|
||||
|
||||
bool StdfsDevice::isfile(std::string_view path) {
|
||||
auto resolved = resolve(path);
|
||||
return std::filesystem::is_regular_file(resolved);
|
||||
return fs::is_regular_file(resolved);
|
||||
}
|
||||
|
||||
void StdfsDevice::mkdirs(std::string_view path) {
|
||||
auto resolved = resolve(path);
|
||||
std::filesystem::create_directories(resolved);
|
||||
fs::create_directories(resolved);
|
||||
}
|
||||
|
||||
bool StdfsDevice::remove(std::string_view path) {
|
||||
auto resolved = resolve(path);
|
||||
return std::filesystem::remove(resolved);
|
||||
return fs::remove(resolved);
|
||||
}
|
||||
|
||||
uint64_t StdfsDevice::removeAll(std::string_view path) {
|
||||
auto resolved = resolve(path);
|
||||
return std::filesystem::remove_all(resolved);
|
||||
return fs::remove_all(resolved);
|
||||
}
|
||||
|
||||
class StdfsPathsGenerator : public PathsGenerator {
|
||||
public:
|
||||
StdfsPathsGenerator(fs::path root) : root(std::move(root)) {
|
||||
it = fs::directory_iterator(this->root);
|
||||
}
|
||||
|
||||
bool next(io::path& path) override {
|
||||
if (it == fs::directory_iterator()) {
|
||||
return false;
|
||||
}
|
||||
path = it->path().filename().u8string();
|
||||
it++;
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
fs::path root;
|
||||
fs::directory_iterator it;
|
||||
};
|
||||
|
||||
std::unique_ptr<PathsGenerator> StdfsDevice::list(std::string_view path) {
|
||||
return std::make_unique<StdfsPathsGenerator>(root / fs::u8path(path));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user