From ba5716c58582a7e52325afe8aa6d51f086696485 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 29 May 2021 18:12:56 +0200 Subject: [PATCH] Skip in-epub file if it is not found, except it's the container. We skipped the whole EPUB before. --- src/zip.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/zip.cpp b/src/zip.cpp index 8139673..4020145 100644 --- a/src/zip.cpp +++ b/src/zip.cpp @@ -39,6 +39,7 @@ namespace epubgrep::zip using boost::locale::translate; using fmt::format; +using std::cerr; std::vector list(const fs::path &filepath) { @@ -112,8 +113,19 @@ std::string read_file(const fs::path &filepath, std::string_view entry_path) close_file(zipfile, filepath); - throw exception{format(translate("{0:s} not found in {1:s}.").str(), + if (entry_path == "META-INF/container.xml") + { // File is probably not an EPUB. + exception e{format(translate("{0:s} not found in {1:s}.").str(), entry_path, filepath.string())}; + e.code = 1; + throw exception{e}; + } + + cerr << translate("WARNING: ") + << format(translate("{0:s} not found in {1:s}.").str(), entry_path, + filepath.string()) + << '\n'; + return {}; } struct archive *open_file(const fs::path &filepath)