fix: prune books missing form sd card in recent books list (#1959)

This commit is contained in:
KemoNine
2026-05-16 22:03:49 +03:00
committed by GitHub
parent a3e51f9b1e
commit 93e81daf41
4 changed files with 26 additions and 14 deletions
+11
View File
@@ -22,6 +22,9 @@ RecentBooksStore RecentBooksStore::instance;
void RecentBooksStore::addBook(const std::string& path, const std::string& title, const std::string& author,
const std::string& coverBmpPath) {
// Drop stale entries first so a new add can't evict a valid book in their stead.
pruneMissing();
// Remove existing entry if present
auto it =
std::find_if(recentBooks.begin(), recentBooks.end(), [&](const RecentBook& book) { return book.path == path; });
@@ -53,6 +56,14 @@ void RecentBooksStore::updateBook(const std::string& path, const std::string& ti
}
}
bool RecentBooksStore::isMissing(const RecentBook& book) { return !Storage.exists(book.path.c_str()); }
bool RecentBooksStore::pruneMissing() {
const size_t before = recentBooks.size();
recentBooks.erase(std::remove_if(recentBooks.begin(), recentBooks.end(), &isMissing), recentBooks.end());
return recentBooks.size() != before;
}
bool RecentBooksStore::saveToFile() const {
Storage.mkdir("/.crosspoint");
return JsonSettingsIO::saveRecentBooks(*this, RECENT_BOOKS_FILE_JSON);