diff --git a/src/utility/rewrite_filesystem.cpp b/src/utility/rewrite_filesystem.cpp index 5ecb82a2..a564a305 100644 --- a/src/utility/rewrite_filesystem.cpp +++ b/src/utility/rewrite_filesystem.cpp @@ -70,6 +70,7 @@ void rewrite_filesystem(logger& lgr, dwarfs::reader::filesystem_v2 const& fs, } size_t block_no{0}; + bool seen_history{false}; auto log_rewrite = [&](bool compressing, auto const& s, @@ -172,6 +173,7 @@ void rewrite_filesystem(logger& lgr, dwarfs::reader::filesystem_v2 const& fs, break; case section_type::HISTORY: + seen_history = true; if (opts.enable_history) { history hist{opts.history}; hist.parse(fs.get_history().serialize().span()); @@ -199,6 +201,18 @@ void rewrite_filesystem(logger& lgr, dwarfs::reader::filesystem_v2 const& fs, } } + if (!seen_history && opts.enable_history) { + history hist{opts.history}; + hist.append(opts.command_line_arguments); + + LOG_VERBOSE << "adding " << get_section_name(section_type::HISTORY) + << ", compressing using '" + << writer.get_compressor(section_type::HISTORY).describe() + << "'"; + + writer.write_history(hist.serialize()); + } + writer.flush(); } diff --git a/test/tool_main_test.cpp b/test/tool_main_test.cpp index c90dd54f..77a3c7c9 100644 --- a/test/tool_main_test.cpp +++ b/test/tool_main_test.cpp @@ -1717,6 +1717,15 @@ TEST_P(mkdwarfs_recompress_test, recompress) { EXPECT_EQ(0, fs.get_history().size()); EXPECT_EQ(1, fs.info_as_json(history_opts).count("history")); EXPECT_THAT(t.err(), ::testing::HasSubstr("removing HISTORY")); + + auto t2 = tester(t.out()); + EXPECT_EQ(0, t2.run({"-i", image_file, "-o", "-", "--recompress=none", + "--log-level=verbose"})) + << t.err(); + auto fs2 = t2.fs_from_stdout(); + EXPECT_TRUE(fs2.find("/random")); + EXPECT_EQ(1, fs2.get_history().size()); + EXPECT_THAT(t2.err(), ::testing::HasSubstr("adding HISTORY")); } {