diff --git a/include/dwarfs/fs_section.h b/include/dwarfs/fs_section.h index 75aa979d..aa0a0ab4 100644 --- a/include/dwarfs/fs_section.h +++ b/include/dwarfs/fs_section.h @@ -38,6 +38,7 @@ class fs_section { size_t length() const { return impl_->length(); } compression_type compression() const { return impl_->compression(); } section_type type() const { return impl_->type(); } + std::string name() const { return impl_->name(); } std::string description() const { return impl_->description(); } bool check_fast(mmif& mm) const { return impl_->check_fast(mm); } bool verify(mmif& mm) const { return impl_->verify(mm); } @@ -52,6 +53,7 @@ class fs_section { virtual size_t length() const = 0; virtual compression_type compression() const = 0; virtual section_type type() const = 0; + virtual std::string name() const = 0; virtual std::string description() const = 0; virtual bool check_fast(mmif& mm) const = 0; virtual bool verify(mmif& mm) const = 0; diff --git a/src/dwarfs/filesystem_v2.cpp b/src/dwarfs/filesystem_v2.cpp index 3b1d2199..6fdb3156 100644 --- a/src/dwarfs/filesystem_v2.cpp +++ b/src/dwarfs/filesystem_v2.cpp @@ -229,13 +229,11 @@ filesystem_::filesystem_(logger& lgr, std::shared_ptr mm, cache.insert(*s); } else { if (!s->check_fast(*mm_)) { - DWARFS_THROW(runtime_error, "checksum error in section: " + - get_section_name(s->type())); + DWARFS_THROW(runtime_error, "checksum error in section: " + s->name()); } if (!sections.emplace(s->type(), *s).second) { - DWARFS_THROW(runtime_error, - "duplicate section: " + get_section_name(s->type())); + DWARFS_THROW(runtime_error, "duplicate section: " + s->name()); } } } @@ -394,19 +392,17 @@ void filesystem_v2::rewrite(logger& lgr, progress& prog, while (auto s = parser.next_section()) { if (!s->check_fast(*mm)) { - DWARFS_THROW(runtime_error, - "checksum error in section: " + get_section_name(s->type())); + DWARFS_THROW(runtime_error, "checksum error in section: " + s->name()); } if (!s->verify(*mm)) { - DWARFS_THROW(runtime_error, "integrity check error in section: " + - get_section_name(s->type())); + DWARFS_THROW(runtime_error, + "integrity check error in section: " + s->name()); } if (s->type() == section_type::BLOCK) { ++prog.block_count; } else { if (!sections.emplace(s->type(), *s).second) { - DWARFS_THROW(runtime_error, - "duplicate section: " + get_section_name(s->type())); + DWARFS_THROW(runtime_error, "duplicate section: " + s->name()); } } } @@ -462,17 +458,15 @@ void filesystem_v2::identify(logger& lgr, std::shared_ptr mm, // TODO: don't throw if we're just checking the file system if (!s->check_fast(*mm)) { - DWARFS_THROW(runtime_error, - "checksum error in section: " + get_section_name(s->type())); + DWARFS_THROW(runtime_error, "checksum error in section: " + s->name()); } if (!s->verify(*mm)) { - DWARFS_THROW(runtime_error, "integrity check error in section: " + - get_section_name(s->type())); + DWARFS_THROW(runtime_error, + "integrity check error in section: " + s->name()); } if (s->type() != section_type::BLOCK) { if (!sections.emplace(s->type(), *s).second) { - DWARFS_THROW(runtime_error, - "duplicate section: " + get_section_name(s->type())); + DWARFS_THROW(runtime_error, "duplicate section: " + s->name()); } } } diff --git a/src/dwarfs/fs_section.cpp b/src/dwarfs/fs_section.cpp index 16d08edb..1319d1ca 100644 --- a/src/dwarfs/fs_section.cpp +++ b/src/dwarfs/fs_section.cpp @@ -38,6 +38,7 @@ class fs_section_v1 : public fs_section::impl { size_t length() const override { return hdr_.length; } compression_type compression() const override { return hdr_.compression; } section_type type() const override { return hdr_.type; } + std::string name() const override { return get_section_name(hdr_.type); } std::string description() const override { return hdr_.to_string(); } bool check_fast(mmif&) const override { return true; } bool verify(mmif&) const override { return true; } @@ -59,6 +60,9 @@ class fs_section_v2 : public fs_section::impl { section_type type() const override { return static_cast(hdr_.type); } + std::string name() const override { + return get_section_name(static_cast(hdr_.type)); + } std::string description() const override { return hdr_.to_string(); } bool check_fast(mmif& mm) const override { auto hdr_cs_len =