diff --git a/firmware/application/file.cpp b/firmware/application/file.cpp index 8c45c8b3..487e53e4 100644 --- a/firmware/application/file.cpp +++ b/firmware/application/file.cpp @@ -126,7 +126,7 @@ Optional File::sync() { static std::filesystem::path find_last_file_matching_pattern(const std::filesystem::path& pattern) { std::filesystem::path last_match; - for(const auto& entry : std::filesystem::directory_iterator(u"", pattern.c_str())) { + for(const auto& entry : std::filesystem::directory_iterator(u"", pattern)) { if( std::filesystem::is_regular_file(entry.status()) ) { const auto match = entry.path(); if( match > last_match ) { @@ -211,11 +211,12 @@ std::string filesystem_error::what() const { } directory_iterator::directory_iterator( - const std::filesystem::path::value_type* path, - const std::filesystem::path::value_type* wild -) { + std::filesystem::path path, + std::filesystem::path wild +) : pattern { wild } +{ impl = std::make_shared(); - const auto result = f_findfirst(&impl->dir, &impl->filinfo, reinterpret_cast(path), reinterpret_cast(wild)); + const auto result = f_findfirst(&impl->dir, &impl->filinfo, reinterpret_cast(path.c_str()), reinterpret_cast(pattern.c_str())); if( result != FR_OK ) { impl.reset(); // TODO: Throw exception if/when I enable exceptions... diff --git a/firmware/application/file.hpp b/firmware/application/file.hpp index 64691703..bc004015 100644 --- a/firmware/application/file.hpp +++ b/firmware/application/file.hpp @@ -97,6 +97,7 @@ class directory_iterator { }; std::shared_ptr impl; + const path pattern; friend bool operator!=(const directory_iterator& lhs, const directory_iterator& rhs); @@ -108,8 +109,8 @@ public: using iterator_category = std::input_iterator_tag; directory_iterator() noexcept { }; - directory_iterator(const std::filesystem::path::value_type* path, const std::filesystem::path::value_type* wild); - + directory_iterator(std::filesystem::path path, std::filesystem::path wild); + ~directory_iterator() { } directory_iterator& operator++();