Fix rewrite of file system

This commit is contained in:
Marcus Holland-Moritz 2020-11-28 02:53:34 +01:00
parent 9b4f365828
commit fc4f1546b2

View File

@ -111,10 +111,11 @@ class filesystem_parser {
using section_map = using section_map =
std::unordered_map<section_type, filesystem_parser::section>; std::unordered_map<section_type, filesystem_parser::section>;
folly::ByteRange get_section_data(std::shared_ptr<mmif> mm, folly::ByteRange
filesystem_parser::section const& section, get_section_data(std::shared_ptr<mmif> mm,
std::vector<uint8_t>& buffer) { filesystem_parser::section const& section,
if (section.header.compression == compression_type::NONE) { std::vector<uint8_t>& buffer, bool force_buffer) {
if (!force_buffer && section.header.compression == compression_type::NONE) {
return mm->range(section.start, section.header.length); return mm->range(section.start, section.header.length);
} }
@ -130,7 +131,7 @@ make_metadata(logger& lgr, std::shared_ptr<mmif> mm,
section_map const& sections, std::vector<uint8_t>& schema_buffer, section_map const& sections, std::vector<uint8_t>& schema_buffer,
std::vector<uint8_t>& meta_buffer, std::vector<uint8_t>& meta_buffer,
const struct ::stat* stat_defaults = nullptr, const struct ::stat* stat_defaults = nullptr,
int inode_offset = 0) { int inode_offset = 0, bool force_buffers = false) {
auto schema_it = sections.find(section_type::METADATA_V2_SCHEMA); auto schema_it = sections.find(section_type::METADATA_V2_SCHEMA);
auto meta_it = sections.find(section_type::METADATA_V2); auto meta_it = sections.find(section_type::METADATA_V2);
@ -142,10 +143,11 @@ make_metadata(logger& lgr, std::shared_ptr<mmif> mm,
throw std::runtime_error("no metadata found"); throw std::runtime_error("no metadata found");
} }
return metadata_v2(lgr, return metadata_v2(
get_section_data(mm, schema_it->second, schema_buffer), lgr,
get_section_data(mm, meta_it->second, meta_buffer), get_section_data(mm, schema_it->second, schema_buffer, force_buffers),
stat_defaults, inode_offset); get_section_data(mm, meta_it->second, meta_buffer, force_buffers),
stat_defaults, inode_offset);
} }
template <typename LoggerPolicy> template <typename LoggerPolicy>
@ -358,7 +360,8 @@ void filesystem_v2::rewrite(logger& lgr, progress& prog,
std::vector<uint8_t> schema_raw; std::vector<uint8_t> schema_raw;
std::vector<uint8_t> meta_raw; std::vector<uint8_t> meta_raw;
auto meta = make_metadata(lgr, mm, sections, schema_raw, meta_raw); auto meta =
make_metadata(lgr, mm, sections, schema_raw, meta_raw, nullptr, 0, true);
struct ::statvfs stbuf; struct ::statvfs stbuf;
meta.statvfs(&stbuf); meta.statvfs(&stbuf);