From 233a5c2dd1bf7275a6c0217b25073acdaee39a63 Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Tue, 26 Apr 2022 12:23:56 +0200 Subject: bug fix: FileRoot::DirectoryEntries cannot hold std::monostate anymore DirectoryEntries must be constructed explicitly either via a GitTree* or an unordered_map. So, the case of an empty directory, is represented by an empty map. Before this patch, empty directories were represented by std::monostate and missing checks on that led to a seg-fault. --- src/buildtool/file_system/file_root.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/buildtool/file_system/file_root.hpp') diff --git a/src/buildtool/file_system/file_root.hpp b/src/buildtool/file_system/file_root.hpp index c374e937..66ceb68a 100644 --- a/src/buildtool/file_system/file_root.hpp +++ b/src/buildtool/file_system/file_root.hpp @@ -84,9 +84,11 @@ class FileRoot { public: class DirectoryEntries { friend class FileRoot; + + public: using pairs_t = std::unordered_map; using tree_t = gsl::not_null; - using entries_t = std::variant; + using entries_t = std::variant; using fs_iterator_type = typename pairs_t::const_iterator; using fs_iterator = FilteredIterator; @@ -94,6 +96,7 @@ class FileRoot { using git_iterator_type = GitTree::entries_t::const_iterator; using git_iterator = FilteredIterator; + private: /// Iterator has two FilteredIterators, one for iterating over pairs_t /// and one for tree_t. Each FilteredIterator is constructed with a /// proper predicate, allowing for iteration on file-only or @@ -146,8 +149,6 @@ class FileRoot { }; public: - DirectoryEntries() noexcept = default; - explicit DirectoryEntries(pairs_t pairs) noexcept : data_{std::move(pairs)} {} @@ -226,7 +227,7 @@ class FileRoot { } private: - entries_t data_{}; + entries_t data_; }; FileRoot() noexcept = default; @@ -346,7 +347,7 @@ class FileRoot { dir_path.string(), ex.what()); } - return {}; + return DirectoryEntries{DirectoryEntries::pairs_t{}}; } [[nodiscard]] auto FileType(std::filesystem::path const& file_path) -- cgit v1.2.3