mirror of
https://github.com/mhx/dwarfs.git
synced 2025-08-05 10:46:13 -04:00
refactor: use file_access
for fragment order parser
This commit is contained in:
parent
f2fc5f3389
commit
179948e0cc
@ -28,14 +28,25 @@
|
|||||||
|
|
||||||
#include <dwarfs/writer/fragment_order_options.h>
|
#include <dwarfs/writer/fragment_order_options.h>
|
||||||
|
|
||||||
namespace dwarfs::writer {
|
namespace dwarfs {
|
||||||
|
|
||||||
|
class file_access;
|
||||||
|
|
||||||
|
namespace writer {
|
||||||
|
|
||||||
struct fragment_order_parser {
|
struct fragment_order_parser {
|
||||||
public:
|
public:
|
||||||
static std::string choices();
|
static std::string choices();
|
||||||
|
|
||||||
|
fragment_order_parser(std::shared_ptr<file_access const> const& fa)
|
||||||
|
: fa_{fa} {}
|
||||||
|
|
||||||
fragment_order_options parse(std::string_view arg) const;
|
fragment_order_options parse(std::string_view arg) const;
|
||||||
std::string to_string(fragment_order_options const& opts) const;
|
std::string to_string(fragment_order_options const& opts) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<file_access const> fa_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dwarfs::writer
|
} // namespace writer
|
||||||
|
} // namespace dwarfs
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include <range/v3/view/join.hpp>
|
#include <range/v3/view/join.hpp>
|
||||||
#include <range/v3/view/map.hpp>
|
#include <range/v3/view/map.hpp>
|
||||||
|
|
||||||
|
#include <dwarfs/file_access.h>
|
||||||
#include <dwarfs/option_map.h>
|
#include <dwarfs/option_map.h>
|
||||||
#include <dwarfs/writer/fragment_order_parser.h>
|
#include <dwarfs/writer/fragment_order_parser.h>
|
||||||
|
|
||||||
@ -99,13 +100,16 @@ fragment_order_parser::parse(std::string_view arg) const {
|
|||||||
|
|
||||||
case fragment_order_mode::EXPLICIT: {
|
case fragment_order_mode::EXPLICIT: {
|
||||||
auto file = om.get<std::string>("file");
|
auto file = om.get<std::string>("file");
|
||||||
std::ifstream ifs{file};
|
std::error_code ec;
|
||||||
if (!ifs) {
|
auto input = fa_->open_input(file, ec);
|
||||||
throw std::runtime_error(
|
|
||||||
fmt::format("failed to open explicit order file '{}'", file));
|
if (ec) {
|
||||||
|
throw std::runtime_error(fmt::format(
|
||||||
|
"failed to open explicit order file '{}': {}", file, ec.message()));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(ifs, line)) {
|
while (std::getline(input->is(), line)) {
|
||||||
auto const path = std::filesystem::path{line}.relative_path();
|
auto const path = std::filesystem::path{line}.relative_path();
|
||||||
rv.explicit_order[path] = rv.explicit_order.size();
|
rv.explicit_order[path] = rv.explicit_order.size();
|
||||||
}
|
}
|
||||||
|
@ -414,7 +414,7 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) {
|
|||||||
integral_value_parser<unsigned> window_size_parser(0, 24);
|
integral_value_parser<unsigned> window_size_parser(0, 24);
|
||||||
integral_value_parser<unsigned> window_step_parser(0, 8);
|
integral_value_parser<unsigned> window_step_parser(0, 8);
|
||||||
integral_value_parser<unsigned> bloom_filter_size_parser(0, 10);
|
integral_value_parser<unsigned> bloom_filter_size_parser(0, 10);
|
||||||
writer::fragment_order_parser order_parser;
|
writer::fragment_order_parser order_parser(iol.file);
|
||||||
block_compressor_parser compressor_parser;
|
block_compressor_parser compressor_parser;
|
||||||
|
|
||||||
writer::scanner_options options;
|
writer::scanner_options options;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user