fix(kosync): reload Epub before reading upload metadata (#2608)

This commit is contained in:
William Floyd
2026-07-15 11:46:10 -04:00
committed by GitHub
parent 95d8cb712b
commit f3cad2f9e1
+15 -3
View File
@@ -208,15 +208,27 @@ void KOReaderSyncActivity::performUpload() {
// Optionally include document metadata (KOReader PR #15306) // Optionally include document metadata (KOReader PR #15306)
if (KOREADER_STORE.getSendMetadata()) { if (KOREADER_STORE.getSendMetadata()) {
// The Epub is released before the sync network calls and is only reloaded on the
// remote-progress path (performSync). When uploading from NO_REMOTE_PROGRESS the
// Epub is still null, so reload it here and guard the title/author reads to avoid
// dereferencing a null Epub. Filename is derived from the path and is always safe.
ensureEpubLoaded();
KOReaderMetadata meta; KOReaderMetadata meta;
// Extract filename from path
const auto lastSlash = epubPath.rfind('/'); const auto lastSlash = epubPath.rfind('/');
meta.filename = (lastSlash != std::string::npos) ? epubPath.substr(lastSlash + 1) : epubPath; meta.filename = (lastSlash != std::string::npos) ? epubPath.substr(lastSlash + 1) : epubPath;
meta.title = epub->getTitle(); if (epub) {
meta.authors = epub->getAuthor(); meta.title = epub->getTitle();
meta.authors = epub->getAuthor();
} else {
LOG_ERR("KOSync", "Epub unavailable for metadata; sending filename only");
}
progress.metadata = std::move(meta); progress.metadata = std::move(meta);
} }
// Release the Epub before the network call so the TLS handshake has enough free heap
// (consistent with the release-before-sync pattern in performSync); nothing below needs it.
epub.reset();
const auto result = KOReaderSyncClient::updateProgress(progress); const auto result = KOReaderSyncClient::updateProgress(progress);
// Drop the radio while user reads the result; full teardown happens at silent reboot. // Drop the radio while user reads the result; full teardown happens at silent reboot.