diff --git a/include/dwarfs/filesystem_writer.h b/include/dwarfs/filesystem_writer.h index 37946644..b10c8b5c 100644 --- a/include/dwarfs/filesystem_writer.h +++ b/include/dwarfs/filesystem_writer.h @@ -33,6 +33,7 @@ #include "dwarfs/compression_constraints.h" #include "dwarfs/fragment_category.h" +#include "dwarfs/fs_section.h" #include "dwarfs/fstypes.h" #include "dwarfs/options.h" #include "dwarfs/worker_group.h" @@ -128,9 +129,8 @@ class filesystem_writer { impl_->write_section(type, compression, data, cat); } - void write_compressed_section(section_type type, compression_type compression, - std::span data) { - impl_->write_compressed_section(type, compression, data); + void write_compressed_section(fs_section sec, std::span data) { + impl_->write_compressed_section(std::move(sec), data); } void flush() { impl_->flush(); } @@ -174,8 +174,7 @@ class filesystem_writer { std::span data, std::optional cat) = 0; virtual void - write_compressed_section(section_type type, compression_type compression, - std::span data) = 0; + write_compressed_section(fs_section sec, std::span data) = 0; virtual void flush() = 0; virtual size_t size() const = 0; }; diff --git a/src/dwarfs/filesystem_v2.cpp b/src/dwarfs/filesystem_v2.cpp index a285346f..1a8c664a 100644 --- a/src/dwarfs/filesystem_v2.cpp +++ b/src/dwarfs/filesystem_v2.cpp @@ -611,8 +611,7 @@ void filesystem_::rewrite(progress& prog, std::optional const& cat = std::nullopt) { log_rewrite(false, s, cat); - writer.write_compressed_section(s->type(), s->compression(), - s->data(*mm_)); + writer.write_compressed_section(*s, s->data(*mm_)); }; auto from_none_to_none = diff --git a/src/dwarfs/filesystem_writer.cpp b/src/dwarfs/filesystem_writer.cpp index 5f08b80d..a1969c5b 100644 --- a/src/dwarfs/filesystem_writer.cpp +++ b/src/dwarfs/filesystem_writer.cpp @@ -84,8 +84,10 @@ class fsblock { folly::Function set_block_cb = nullptr); fsblock(section_type type, compression_type compression, - std::span data, - std::shared_ptr pctx = nullptr); + std::span data); + + fsblock(fs_section sec, std::span data, + std::shared_ptr pctx); fsblock(section_type type, block_compressor const& bc, std::span data, compression_type data_comp_type, @@ -255,12 +257,18 @@ class raw_fsblock : public fsblock::impl { class compressed_fsblock : public fsblock::impl { public: compressed_fsblock(section_type type, compression_type compression, - std::span range, - std::shared_ptr pctx) + std::span range) : type_{type} , compression_{compression} + , range_{range} {} + + compressed_fsblock(fs_section sec, std::span range, + std::shared_ptr pctx) + : type_{sec.type()} + , compression_{sec.compression()} , range_{range} - , pctx_{std::move(pctx)} {} + , pctx_{std::move(pctx)} + , sec_{std::move(sec)} {} void compress(worker_group& wg, std::optional /* meta */) override { @@ -303,6 +311,7 @@ class compressed_fsblock : public fsblock::impl { std::optional number_; section_header_v2 header_; std::shared_ptr pctx_; + std::optional sec_; }; class rewritten_fsblock : public fsblock::impl { @@ -420,9 +429,12 @@ fsblock::fsblock(section_type type, block_compressor const& bc, std::move(set_block_cb))) {} fsblock::fsblock(section_type type, compression_type compression, - std::span data, + std::span data) + : impl_(std::make_unique(type, compression, data)) {} + +fsblock::fsblock(fs_section sec, std::span data, std::shared_ptr pctx) - : impl_(std::make_unique(type, compression, data, + : impl_(std::make_unique(std::move(sec), data, std::move(pctx))) {} fsblock::fsblock(section_type type, block_compressor const& bc, @@ -497,7 +509,7 @@ class filesystem_writer_ final : public filesystem_writer::impl { void write_section(section_type type, compression_type compression, std::span data, std::optional cat) override; - void write_compressed_section(section_type type, compression_type compression, + void write_compressed_section(fs_section sec, std::span data) override; void flush() override; size_t size() const override { return os_.tellp(); } @@ -861,8 +873,7 @@ void filesystem_writer_::write_section( template void filesystem_writer_::write_compressed_section( - section_type type, compression_type compression, - std::span data) { + fs_section sec, std::span data) { { std::lock_guard lock(mx_); @@ -870,7 +881,7 @@ void filesystem_writer_::write_compressed_section( pctx_ = prog_.create_context(); } - auto fsb = std::make_unique(type, compression, data, pctx_); + auto fsb = std::make_unique(std::move(sec), data, pctx_); fsb->set_block_no(section_number_++); fsb->compress(wg_);