From 47f09ad8fb52de7ee9ed6c63574ea2f77e314fa2 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Sat, 23 Oct 2021 02:24:24 +0200 Subject: Sort filenames alpha-numeric, used as template system dependency management. Signed-off-by: Toni Uhlig --- src/Filesystem.cpp | 15 +++++++++++++++ src/Filesystem.hpp | 1 + src/TemplateManager.cpp | 12 ++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Filesystem.cpp b/src/Filesystem.cpp index 9fe13bb..f3824e3 100644 --- a/src/Filesystem.cpp +++ b/src/Filesystem.cpp @@ -135,6 +135,21 @@ FilesDict & Filesystem::GetFiles() return m_Files; } +void Filesystem::GetFilenamesSorted(std::vector & sortedFilenames) +{ + for (auto const & f : GetFiles()) + { + sortedFilenames.push_back(f.first); + } + std::sort(sortedFilenames.begin(), sortedFilenames.end()); +#if 1 + for (auto const & f : sortedFilenames) + { + std::cout << "Added file (alnum sorted): " << f << std::endl; + } +#endif +} + void Filesystem::MagicInit() { m_Magic = magic_open(MAGIC_MIME_TYPE); diff --git a/src/Filesystem.hpp b/src/Filesystem.hpp index 98fbdcd..a87c0a3 100644 --- a/src/Filesystem.hpp +++ b/src/Filesystem.hpp @@ -32,6 +32,7 @@ public: bool Scan(std::string root = "./wwwroot"); bool Scan(std::string root, std::vector extensions, bool exclude_extensions = false); FilesDict & GetFiles(); + void GetFilenamesSorted(std::vector & sortedFilenames); private: bool AddSingleFile(std::string path, std::string root); diff --git a/src/TemplateManager.cpp b/src/TemplateManager.cpp index 62b4e27..2c58306 100644 --- a/src/TemplateManager.cpp +++ b/src/TemplateManager.cpp @@ -38,11 +38,15 @@ TemplateManager::TemplateManager() void TemplateManager::ParseTemplates(Filesystem & fs) { - for (auto & tpl : fs.GetFiles()) + std::vector sortedFilenames; + auto & files = fs.GetFiles(); + + fs.GetFilenamesSorted(sortedFilenames); + for (auto const & tpl : sortedFilenames) { - std::string tmpl(tpl.second.data.data(), tpl.second.data.data() + tpl.second.data.size()); - m_Inja.include_template(tpl.first, m_Inja.parse(tmpl)); - std::cout << "File: " << tpl.first << " may contain a renderable template." << std::endl; + std::string tmpl(files[tpl].data.data(), files[tpl].data.data() + files[tpl].data.size()); + m_Inja.include_template(tpl, m_Inja.parse(tmpl)); + std::cout << "File: " << tpl << " may contain a renderable template." << std::endl; } } -- cgit v1.2.3