Skip to content

Commit

Permalink
OstreeMutableTree: Invalidate parent contents checksum when metadata …
Browse files Browse the repository at this point in the history
…changes

This bug has existed before the previous commit, but thanks to the previous
commit it is now easy to fix.
  • Loading branch information
wmanley committed Jun 26, 2018
1 parent 1c1be48 commit 3c091e4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/libostree/ostree-mutable-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ void
ostree_mutable_tree_set_metadata_checksum (OstreeMutableTree *self,
const char *checksum)
{
if (g_strcmp0 (checksum, self->metadata_checksum) == 0)
return;

invalidate_contents_checksum (self->parent);
g_free (self->metadata_checksum);
self->metadata_checksum = g_strdup (checksum);
}
Expand Down
22 changes: 22 additions & 0 deletions tests/test-mutable-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
static void
test_metadata_checksum (void)
{
g_autoptr(GError) error = NULL;
const char *checksum = "12345678901234567890123456789012";
glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new ();

Expand All @@ -39,6 +40,27 @@ test_metadata_checksum (void)
ostree_mutable_tree_set_metadata_checksum (tree, checksum);

g_assert_cmpstr (checksum, ==, ostree_mutable_tree_get_metadata_checksum (tree));

/* If a child tree's metadata changes the parent tree's contents needs to be
* recalculated */
glnx_unref_object OstreeMutableTree *subdir = NULL;
g_assert (ostree_mutable_tree_ensure_dir (tree, "subdir", &subdir, &error));
g_assert_nonnull (subdir);

ostree_mutable_tree_set_contents_checksum (
subdir, "11111111111111111111111111111111");
ostree_mutable_tree_set_metadata_checksum (
subdir, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
ostree_mutable_tree_set_contents_checksum (
tree, "abcdefabcdefabcdefabcdefabcdefab");

g_assert_cmpstr (ostree_mutable_tree_get_contents_checksum (tree), ==,
"abcdefabcdefabcdefabcdefabcdefab");
ostree_mutable_tree_set_metadata_checksum (
subdir, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
g_assert_null (ostree_mutable_tree_get_contents_checksum (tree));
g_assert_cmpstr (ostree_mutable_tree_get_contents_checksum (subdir), ==,
"11111111111111111111111111111111");
}

static void
Expand Down

0 comments on commit 3c091e4

Please sign in to comment.