Add lots of debug output.
This commit is contained in:
parent
017059cb5b
commit
07915bdf87
|
@ -17,6 +17,7 @@
|
||||||
#include "files.hpp"
|
#include "files.hpp"
|
||||||
|
|
||||||
#include "fs-compat.hpp"
|
#include "fs-compat.hpp"
|
||||||
|
#include "log.hpp"
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
@ -42,6 +43,7 @@ std::vector<fs::path> list_recursive(const fs::path &directory,
|
||||||
if (!path.is_directory())
|
if (!path.is_directory())
|
||||||
{
|
{
|
||||||
paths.emplace_back(path);
|
paths.emplace_back(path);
|
||||||
|
DEBUGLOG << "Added file: " << path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,7 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
log::enable_debug();
|
log::enable_debug();
|
||||||
}
|
}
|
||||||
|
DEBUGLOG << "Options: " << opts;
|
||||||
|
|
||||||
if (opts.help || opts.version)
|
if (opts.help || opts.version)
|
||||||
{
|
{
|
||||||
|
@ -97,8 +98,8 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (!opts.recursive && !opts.dereference_recursive)
|
if (!opts.recursive && !opts.dereference_recursive)
|
||||||
{
|
{
|
||||||
|
|
||||||
input_files.emplace_back(filepath);
|
input_files.emplace_back(filepath);
|
||||||
|
DEBUGLOG << "Added to input_files: " << filepath;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -109,12 +110,14 @@ int main(int argc, char *argv[])
|
||||||
opts.dereference_recursive)};
|
opts.dereference_recursive)};
|
||||||
input_files.insert(input_files.end(), files_in_dir.begin(),
|
input_files.insert(input_files.end(), files_in_dir.begin(),
|
||||||
files_in_dir.end());
|
files_in_dir.end());
|
||||||
|
DEBUGLOG << "Added directory to input_files.";
|
||||||
}
|
}
|
||||||
catch (const fs::filesystem_error &e)
|
catch (const fs::filesystem_error &e)
|
||||||
{
|
{
|
||||||
if (e.code().value() == 20)
|
if (e.code().value() == 20)
|
||||||
{ // Is not a directory.
|
{ // Is not a directory.
|
||||||
input_files.emplace_back(filepath);
|
input_files.emplace_back(filepath);
|
||||||
|
DEBUGLOG << "Added to input_files: " << filepath;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,15 +206,18 @@ int main(int argc, char *argv[])
|
||||||
auto n{static_cast<double>(std::thread::hardware_concurrency())};
|
auto n{static_cast<double>(std::thread::hardware_concurrency())};
|
||||||
return static_cast<std::uint32_t>(std::ceil(n / 2 + n / 4));
|
return static_cast<std::uint32_t>(std::ceil(n / 2 + n / 4));
|
||||||
}()};
|
}()};
|
||||||
|
DEBUGLOG << "max_threads = " << max_threads;
|
||||||
|
|
||||||
for (const auto &filepath : input_files)
|
for (const auto &filepath : input_files)
|
||||||
{
|
{
|
||||||
while (futurepool.size() >= max_threads)
|
while (futurepool.size() >= max_threads)
|
||||||
{
|
{
|
||||||
|
DEBUGLOG << "Attempting to clean up threads";
|
||||||
futures_cleanup();
|
futures_cleanup();
|
||||||
}
|
}
|
||||||
futurepool.emplace_back(
|
futurepool.emplace_back(
|
||||||
std::async(std::launch::async, search_file, filepath));
|
std::async(std::launch::async, search_file, filepath));
|
||||||
|
DEBUGLOG << "Launched new thread";
|
||||||
|
|
||||||
if (!matches_all.empty())
|
if (!matches_all.empty())
|
||||||
{
|
{
|
||||||
|
@ -221,6 +227,7 @@ int main(int argc, char *argv[])
|
||||||
matches_all.erase(matches_all.begin());
|
matches_all.erase(matches_all.begin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DEBUGLOG << "Waiting for remaining threads to finish";
|
||||||
futures_cleanup(true);
|
futures_cleanup(true);
|
||||||
|
|
||||||
for (const auto &matches : matches_all)
|
for (const auto &matches : matches_all)
|
||||||
|
|
|
@ -18,9 +18,12 @@
|
||||||
|
|
||||||
#include "fs-compat.hpp"
|
#include "fs-compat.hpp"
|
||||||
#include "helpers.hpp"
|
#include "helpers.hpp"
|
||||||
|
#include "log.hpp"
|
||||||
#include "zip.hpp"
|
#include "zip.hpp"
|
||||||
|
|
||||||
#include <boost/regex.hpp>
|
#include <boost/regex.hpp>
|
||||||
|
#include <fmt/format.h>
|
||||||
|
#include <fmt/ostream.h> // For compatibility with fmt 4.
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
@ -31,11 +34,14 @@
|
||||||
namespace epubgrep::search
|
namespace epubgrep::search
|
||||||
{
|
{
|
||||||
|
|
||||||
|
using fmt::format;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
std::vector<match> search(const fs::path &filepath,
|
std::vector<match> search(const fs::path &filepath,
|
||||||
const std::string_view regex, const settings &opts)
|
const std::string_view regex, const settings &opts)
|
||||||
{
|
{
|
||||||
|
DEBUGLOG << format(R"(Starting search in {0:s} using regex "{1:s}")",
|
||||||
|
filepath, regex);
|
||||||
boost::regex::flag_type flags{};
|
boost::regex::flag_type flags{};
|
||||||
|
|
||||||
switch (opts.regex)
|
switch (opts.regex)
|
||||||
|
@ -75,6 +81,7 @@ std::vector<match> search(const fs::path &filepath,
|
||||||
|
|
||||||
for (const auto &entry : epub_filepaths)
|
for (const auto &entry : epub_filepaths)
|
||||||
{
|
{
|
||||||
|
DEBUGLOG << "Processing " << entry;
|
||||||
auto document{zip::read_file(filepath, entry)};
|
auto document{zip::read_file(filepath, entry)};
|
||||||
if (!opts.raw)
|
if (!opts.raw)
|
||||||
{
|
{
|
||||||
|
|
15
src/zip.cpp
15
src/zip.cpp
|
@ -61,6 +61,7 @@ std::vector<std::string> list(const fs::path &filepath)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
toc.emplace_back(in_epub_filepath);
|
toc.emplace_back(in_epub_filepath);
|
||||||
|
DEBUGLOG << "Found in file: " << in_epub_filepath;
|
||||||
archive_read_data_skip(zipfile);
|
archive_read_data_skip(zipfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +190,7 @@ std::vector<std::string> list_spine(const fs::path &filepath)
|
||||||
std::vector<std::string> spine_filepaths;
|
std::vector<std::string> spine_filepaths;
|
||||||
if (!opf_file_path.empty())
|
if (!opf_file_path.empty())
|
||||||
{
|
{
|
||||||
|
DEBUGLOG << "Parsing " << opf_file_path;
|
||||||
pugi::xml_document xml;
|
pugi::xml_document xml;
|
||||||
const std::string opf_file{read_file(filepath, opf_file_path.string())};
|
const std::string opf_file{read_file(filepath, opf_file_path.string())};
|
||||||
const auto result{xml.load_buffer(&opf_file[0], opf_file.size())};
|
const auto result{xml.load_buffer(&opf_file[0], opf_file.size())};
|
||||||
|
@ -209,15 +211,20 @@ std::vector<std::string> list_spine(const fs::path &filepath)
|
||||||
{
|
{
|
||||||
const auto &idref{itemref.attribute("idref").value()};
|
const auto &idref{itemref.attribute("idref").value()};
|
||||||
const auto &item{manifest.find_child_by_attribute("id", idref)};
|
const auto &item{manifest.find_child_by_attribute("id", idref)};
|
||||||
const std::string href{
|
const auto href{
|
||||||
helpers::urldecode(item.attribute("href").value())};
|
helpers::urldecode(item.attribute("href").value())};
|
||||||
|
const auto real_href{
|
||||||
|
[&href, &spine_filepaths, &opf_file_path]
|
||||||
|
{
|
||||||
if (href[0] != '/')
|
if (href[0] != '/')
|
||||||
{
|
{
|
||||||
spine_filepaths.emplace_back(
|
return spine_filepaths.emplace_back(
|
||||||
opf_file_path.parent_path() /= href);
|
opf_file_path.parent_path() /= href);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
spine_filepaths.emplace_back(href);
|
return href;
|
||||||
|
}()};
|
||||||
|
DEBUGLOG << "Found in spine: " << real_href;
|
||||||
|
spine_filepaths.emplace_back(real_href);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user