From 1573a8c4cde1cd9528b422b2dcc598e37ffe94a7 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 2 May 2024 19:12:26 +1000 Subject: WIP merge cyclically dependent components into one big component --- src/tangara/database/file_gatherer.cpp | 80 ++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/tangara/database/file_gatherer.cpp (limited to 'src/tangara/database/file_gatherer.cpp') diff --git a/src/tangara/database/file_gatherer.cpp b/src/tangara/database/file_gatherer.cpp new file mode 100644 index 00000000..b7b7271e --- /dev/null +++ b/src/tangara/database/file_gatherer.cpp @@ -0,0 +1,80 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include "file_gatherer.hpp" + +#include +#include +#include +#include + +#include "ff.h" + +#include "memory_resource.hpp" +#include "spi.hpp" + +namespace database { + +static_assert(sizeof(TCHAR) == sizeof(char), "TCHAR must be CHAR"); + +auto FileGathererImpl::FindFiles( + const std::string& root, + std::function cb) -> void { + std::pmr::deque to_explore{&memory::kSpiRamResource}; + to_explore.push_back({root.data(), root.size()}); + + while (!to_explore.empty()) { + auto next_path_str = to_explore.front(); + to_explore.pop_front(); + + const TCHAR* next_path = static_cast(next_path_str.c_str()); + + FF_DIR dir; + FRESULT res; + { + auto lock = drivers::acquire_spi(); + res = f_opendir(&dir, next_path); + } + if (res != FR_OK) { + // TODO: log. + continue; + } + + for (;;) { + FILINFO info; + { + auto lock = drivers::acquire_spi(); + res = f_readdir(&dir, &info); + } + if (res != FR_OK || info.fname[0] == 0) { + // No more files in the directory. + break; + } else if (info.fattrib & (AM_HID | AM_SYS) || info.fname[0] == '.') { + // System or hidden file. Ignore it and move on. + continue; + } else { + std::pmr::string full_path{&memory::kSpiRamResource}; + full_path += next_path_str; + full_path += "/"; + full_path += info.fname; + + if (info.fattrib & AM_DIR) { + // This is a directory. Add it to the explore queue. + to_explore.push_back(full_path); + } else { + // This is a file! Let the callback know about it. + // std::invoke(cb, full_path.str(), info); + std::invoke(cb, full_path, info); + } + } + } + + auto lock = drivers::acquire_spi(); + f_closedir(&dir); + } +} + +} // namespace database -- cgit v1.2.3 From 7d7f7755d17e1e0a2348d75d797097f166b70471 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 2 May 2024 21:41:56 +1000 Subject: start moving include files into subdirs --- src/tangara/database/file_gatherer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tangara/database/file_gatherer.cpp') diff --git a/src/tangara/database/file_gatherer.cpp b/src/tangara/database/file_gatherer.cpp index b7b7271e..141259c2 100644 --- a/src/tangara/database/file_gatherer.cpp +++ b/src/tangara/database/file_gatherer.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: GPL-3.0-only */ -#include "file_gatherer.hpp" +#include "database/file_gatherer.hpp" #include #include -- cgit v1.2.3 From 26eb580043ad176bdc58d996f30d470e1073ef00 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 2 May 2024 21:52:59 +1000 Subject: move driver includes into a subdir as well --- src/tangara/database/file_gatherer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tangara/database/file_gatherer.cpp') diff --git a/src/tangara/database/file_gatherer.cpp b/src/tangara/database/file_gatherer.cpp index 141259c2..75a1af27 100644 --- a/src/tangara/database/file_gatherer.cpp +++ b/src/tangara/database/file_gatherer.cpp @@ -13,8 +13,8 @@ #include "ff.h" +#include "drivers/spi.hpp" #include "memory_resource.hpp" -#include "spi.hpp" namespace database { -- cgit v1.2.3