refactor: unify book cache clearing for epub, txt, and xtc files (#1875)

This commit is contained in:
WuTofu
2026-05-21 14:44:10 +03:00
committed by GitHub
parent dc404b41c7
commit 2dd491b62e
9 changed files with 77 additions and 32 deletions
+34
View File
@@ -0,0 +1,34 @@
#include "BookCacheUtils.h"
#include <Epub.h>
#include <FsHelpers.h>
#include <Logging.h>
#include <Txt.h>
#include <Xtc.h>
bool isBookCacheDirectoryName(const char* name) {
if (!name) {
return false;
}
constexpr char EPUB_PREFIX[] = "epub_";
constexpr char TXT_PREFIX[] = "txt_";
constexpr char XTC_PREFIX[] = "xtc_";
return strncmp(name, EPUB_PREFIX, std::size(EPUB_PREFIX) - 1) == 0 ||
strncmp(name, TXT_PREFIX, std::size(TXT_PREFIX) - 1) == 0 ||
strncmp(name, XTC_PREFIX, std::size(XTC_PREFIX) - 1) == 0;
}
void clearBookCache(const std::string& path) {
if (FsHelpers::hasEpubExtension(path)) {
Epub(path, "/.crosspoint").clearCache();
} else if (FsHelpers::hasXtcExtension(path)) {
Xtc(path, "/.crosspoint").clearCache();
} else if (FsHelpers::hasTxtExtension(path)) {
Txt(path, "/.crosspoint").clearCache();
} else {
return;
}
LOG_DBG("BookCache", "Done checking metadata cache for: %s", path.c_str());
}