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