diff --git a/include/dwarfs/writer/categorizer.h b/include/dwarfs/writer/categorizer.h index a3927ea6..cc430c66 100644 --- a/include/dwarfs/writer/categorizer.h +++ b/include/dwarfs/writer/categorizer.h @@ -43,6 +43,7 @@ class variables_map; namespace dwarfs { +class file_access; class logger; namespace writer { @@ -224,8 +225,8 @@ class categorizer_info { class categorizer_factory : public categorizer_info { public: virtual std::unique_ptr - create(logger& lgr, - boost::program_options::variables_map const& vm) const = 0; + create(logger& lgr, boost::program_options::variables_map const& vm, + std::shared_ptr const& fa) const = 0; }; class categorizer_registry { @@ -234,7 +235,8 @@ class categorizer_registry { std::unique_ptr create(logger& lgr, std::string const& name, - boost::program_options::variables_map const& vm) const; + boost::program_options::variables_map const& vm, + std::shared_ptr const& fa) const; void add_options(boost::program_options::options_description& opts) const; diff --git a/src/writer/categorizer.cpp b/src/writer/categorizer.cpp index 8352bb85..e5e40ddc 100644 --- a/src/writer/categorizer.cpp +++ b/src/writer/categorizer.cpp @@ -400,16 +400,16 @@ void categorizer_registry::register_factory( } } -std::unique_ptr -categorizer_registry::create(logger& lgr, std::string const& name, - po::variables_map const& vm) const { +std::unique_ptr categorizer_registry::create( + logger& lgr, std::string const& name, po::variables_map const& vm, + std::shared_ptr const& fa) const { auto it = factories_.find(name); if (it == factories_.end()) { DWARFS_THROW(runtime_error, "unknown categorizer: " + name); } - return it->second->create(lgr, vm); + return it->second->create(lgr, vm, fa); } void categorizer_registry::add_options(po::options_description& opts) const { diff --git a/src/writer/categorizer/fits_categorizer.cpp b/src/writer/categorizer/fits_categorizer.cpp index db6a5ffa..332e2b75 100644 --- a/src/writer/categorizer/fits_categorizer.cpp +++ b/src/writer/categorizer/fits_categorizer.cpp @@ -454,7 +454,8 @@ class fits_categorizer_factory : public categorizer_factory { } std::unique_ptr - create(logger& lgr, po::variables_map const& /*vm*/) const override { + create(logger& lgr, po::variables_map const& /*vm*/, + std::shared_ptr const& /*fa*/) const override { return make_unique_logging_object(lgr); } diff --git a/src/writer/categorizer/hotness_categorizer.cpp b/src/writer/categorizer/hotness_categorizer.cpp index d0817773..3cd162aa 100644 --- a/src/writer/categorizer/hotness_categorizer.cpp +++ b/src/writer/categorizer/hotness_categorizer.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -33,6 +32,7 @@ #include #include +#include #include #include #include @@ -52,7 +52,8 @@ struct hotness_categorizer_config { template class hotness_categorizer_ final : public random_access_categorizer { public: - hotness_categorizer_(logger& lgr, hotness_categorizer_config const& cfg); + hotness_categorizer_(logger& lgr, hotness_categorizer_config const& cfg, + std::shared_ptr const& fa); std::span categories() const override; @@ -72,20 +73,23 @@ class hotness_categorizer_ final : public random_access_categorizer { template hotness_categorizer_::hotness_categorizer_( - logger& lgr, hotness_categorizer_config const& cfg) + logger& lgr, hotness_categorizer_config const& cfg, + std::shared_ptr const& fa) : LOG_PROXY_INIT(lgr) , cfg_{cfg} { auto const& file = cfg_.hotness_list; if (!file.empty()) { - std::ifstream ifs{file}; - if (!ifs) { - DWARFS_THROW(runtime_error, - fmt::format("failed to open file '{}'", file)); + std::error_code ec; + auto input = fa->open_input(file, ec); + + if (ec) { + DWARFS_THROW(runtime_error, fmt::format("failed to open file '{}': {}", + file, ec.message())); } std::string line; - while (std::getline(ifs, line)) { + while (std::getline(input->is(), line)) { auto const path = std::filesystem::path{line}.relative_path(); LOG_DEBUG << "hotness categorizer: adding path '" << path << "'"; if (!hotness_set_.emplace(path.string()).second) { @@ -118,7 +122,8 @@ inode_fragments hotness_categorizer_::categorize( if (!hotness_set_.empty()) { auto const rel_path = path.relative_path(); - LOG_DEBUG << "hotness categorizer: checking path '" << rel_path << "'"; + LOG_DEBUG << "hotness categorizer: checking path '" << rel_path << "' ('" + << path.full_path() << "')"; if (auto it = hotness_set_.find(rel_path.string()); it != hotness_set_.end()) { @@ -163,9 +168,10 @@ class hotness_categorizer_factory : public categorizer_factory { } std::unique_ptr - create(logger& lgr, po::variables_map const& /*vm*/) const override { + create(logger& lgr, po::variables_map const& /*vm*/, + std::shared_ptr const& fa) const override { return make_unique_logging_object(lgr, cfg_); + logger_policies>(lgr, cfg_, fa); } private: diff --git a/src/writer/categorizer/incompressible_categorizer.cpp b/src/writer/categorizer/incompressible_categorizer.cpp index 2ff7a410..b3d65472 100644 --- a/src/writer/categorizer/incompressible_categorizer.cpp +++ b/src/writer/categorizer/incompressible_categorizer.cpp @@ -291,7 +291,8 @@ class incompressible_categorizer_factory : public categorizer_factory { } std::unique_ptr - create(logger& lgr, po::variables_map const& /*vm*/) const override { + create(logger& lgr, po::variables_map const& /*vm*/, + std::shared_ptr const& /*fa*/) const override { auto cfg = cfg_; cfg.min_input_size = parse_size_with_unit(min_input_size_str_); cfg.block_size = parse_size_with_unit(block_size_str_); diff --git a/src/writer/categorizer/pcmaudio_categorizer.cpp b/src/writer/categorizer/pcmaudio_categorizer.cpp index 687814dc..caeb3fc0 100644 --- a/src/writer/categorizer/pcmaudio_categorizer.cpp +++ b/src/writer/categorizer/pcmaudio_categorizer.cpp @@ -1168,7 +1168,8 @@ class pcmaudio_categorizer_factory : public categorizer_factory { } std::unique_ptr - create(logger& lgr, po::variables_map const& /*vm*/) const override { + create(logger& lgr, po::variables_map const& /*vm*/, + std::shared_ptr const& /*fa*/) const override { return make_unique_logging_object(lgr); } diff --git a/test/fits_categorizer_test.cpp b/test/fits_categorizer_test.cpp index 52aace7f..2a0e30d4 100644 --- a/test/fits_categorizer_test.cpp +++ b/test/fits_categorizer_test.cpp @@ -70,7 +70,7 @@ class fits_categorizer_fixture : public Base { catmgr = std::make_shared(lgr, "/"); - catmgr->add(catreg.create(lgr, "fits", vm)); + catmgr->add(catreg.create(lgr, "fits", vm, nullptr)); } public: diff --git a/test/incompressible_categorizer_test.cpp b/test/incompressible_categorizer_test.cpp index 42fdbb32..bfb682d6 100644 --- a/test/incompressible_categorizer_test.cpp +++ b/test/incompressible_categorizer_test.cpp @@ -94,7 +94,7 @@ class incompressible_categorizer_fixture : public Base { catmgr = std::make_shared(lgr, "/"); - catmgr->add(catreg.create(lgr, "incompressible", vm)); + catmgr->add(catreg.create(lgr, "incompressible", vm, nullptr)); } // void TearDown() override { diff --git a/test/pcmaudio_categorizer_test.cpp b/test/pcmaudio_categorizer_test.cpp index 9f078888..d89a7055 100644 --- a/test/pcmaudio_categorizer_test.cpp +++ b/test/pcmaudio_categorizer_test.cpp @@ -217,7 +217,7 @@ TEST(pcmaudio_categorizer, requirements) { auto& catreg = writer::categorizer_registry::instance(); auto catmgr = writer::categorizer_manager(logger, "/"); - catmgr.add(catreg.create(logger, "pcmaudio", vm)); + catmgr.add(catreg.create(logger, "pcmaudio", vm, nullptr)); try { catmgr.set_metadata_requirements( @@ -307,7 +307,7 @@ class pcmaudio_error_test : public testing::Test { void SetUp() override { boost::program_options::variables_map vm; auto& catreg = writer::categorizer_registry::instance(); - catmgr.add(catreg.create(logger, "pcmaudio", vm)); + catmgr.add(catreg.create(logger, "pcmaudio", vm, nullptr)); catmgr.set_metadata_requirements( catmgr.category_value("pcmaudio/waveform").value(), diff --git a/tools/src/mkdwarfs_main.cpp b/tools/src/mkdwarfs_main.cpp index 725b5caf..7ac8ea4e 100644 --- a/tools/src/mkdwarfs_main.cpp +++ b/tools/src/mkdwarfs_main.cpp @@ -762,7 +762,7 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) { for (auto const& name : catreg.categorizer_names()) { stream_logger lgr(iol.term, iol.err); - auto categorizer = catreg.create(lgr, name, vm); + auto categorizer = catreg.create(lgr, name, vm, iol.file); iol.out << " [" << name << "]\n"; for (auto cat : categorizer->categories()) { iol.out << " " << cat << "\n"; @@ -1187,7 +1187,8 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) { std::make_shared(lgr, path); for (auto const& name : categorizers) { - options.inode.categorizer_mgr->add(catreg.create(lgr, name, vm)); + options.inode.categorizer_mgr->add( + catreg.create(lgr, name, vm, iol.file)); } }