fix(rewrite_filesystem): add history unless --no-history is given

This commit is contained in:
Marcus Holland-Moritz 2025-05-11 16:09:16 +02:00
parent f01cf2c76a
commit 3a49825eca
2 changed files with 23 additions and 0 deletions

View File

@ -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();
}

View File

@ -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"));
}
{