mirror of
https://github.com/mhx/dwarfs.git
synced 2025-08-03 09:47:01 -04:00
fix(rewrite_filesystem): add history unless --no-history
is given
This commit is contained in:
parent
f01cf2c76a
commit
3a49825eca
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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"));
|
||||
}
|
||||
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user