summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-02-05 11:27:09 +1100
committerjacqueline <me@jacqueline.id.au>2024-02-05 11:27:09 +1100
commit0f03efe868f4a7910678a0a729f437a2fe8986b7 (patch)
tree11992f2ef907773c67b244250fb7339963addf4f /src
parent299f3cc48f683d3e6dec1efb4957fdb49b4de2c3 (diff)
downloadtangara-fw-0f03efe868f4a7910678a0a729f437a2fe8986b7.tar.gz
Make db updates more robust again the sd card disappearing
Accidentally found a bug while live on youtube :)
Diffstat (limited to 'src')
-rw-r--r--src/database/database.cpp23
-rw-r--r--src/database/file_gatherer.cpp3
2 files changed, 19 insertions, 7 deletions
diff --git a/src/database/database.cpp b/src/database/database.cpp
index 141482ed..15e7060d 100644
--- a/src/database/database.cpp
+++ b/src/database/database.cpp
@@ -274,12 +274,27 @@ auto Database::getIndexes() -> std::vector<IndexInfo> {
};
}
+class UpdateNotifier {
+ public:
+ UpdateNotifier(std::atomic<bool>& is_updating) : is_updating_(is_updating) {
+ events::Ui().Dispatch(event::UpdateStarted{});
+ events::System().Dispatch(event::UpdateStarted{});
+ }
+ ~UpdateNotifier() {
+ is_updating_ = false;
+ events::Ui().Dispatch(event::UpdateFinished{});
+ events::System().Dispatch(event::UpdateFinished{});
+ }
+
+ private:
+ std::atomic<bool>& is_updating_;
+};
+
auto Database::updateIndexes() -> void {
if (is_updating_.exchange(true)) {
return;
}
- events::Ui().Dispatch(event::UpdateStarted{});
- events::System().Dispatch(event::UpdateStarted{});
+ UpdateNotifier notifier{is_updating_};
leveldb::ReadOptions read_options;
read_options.fill_cache = false;
@@ -453,10 +468,6 @@ auto Database::updateIndexes() -> void {
dbSetLastUpdate(newest_track);
ESP_LOGI(kTag, "newest track was at %u,%u", newest_track.first,
newest_track.second);
-
- is_updating_ = false;
- events::Ui().Dispatch(event::UpdateFinished{});
- events::System().Dispatch(event::UpdateFinished{});
}
auto Database::isUpdating() -> bool {
diff --git a/src/database/file_gatherer.cpp b/src/database/file_gatherer.cpp
index f07a1b4d..dde363bd 100644
--- a/src/database/file_gatherer.cpp
+++ b/src/database/file_gatherer.cpp
@@ -28,6 +28,8 @@ auto FileGathererImpl::FindFiles(
while (!to_explore.empty()) {
std::string next_path_str = to_explore.front();
+ to_explore.pop_front();
+
const TCHAR* next_path = static_cast<const TCHAR*>(next_path_str.c_str());
FF_DIR dir;
@@ -72,7 +74,6 @@ auto FileGathererImpl::FindFiles(
auto lock = drivers::acquire_spi();
f_closedir(&dir);
- to_explore.pop_front();
}
}