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.

Closes: #1655
Approved by: cgwalters
  • Loading branch information
wmanley authored and rh-atomic-bot committed Jun 29, 2018
1 parent 5ecbdbb commit 7453b30
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/libostree/ostree-mutable-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ invalidate_contents_checksum (OstreeMutableTree *self)
if (!self->contents_checksum)
break;

g_free (self->contents_checksum);
g_clear_pointer (&self->contents_checksum, g_free);
self = self->parent;
}
Expand All @@ -158,6 +157,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
25 changes: 23 additions & 2 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 Expand Up @@ -162,13 +184,12 @@ test_contents_checksum (void)
const char *subdir_checksum = "ABCD0123456789012345678901234567";
glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new ();
glnx_unref_object OstreeMutableTree *subdir = NULL;
g_autoptr(GError) error = NULL;
g_assert_null (ostree_mutable_tree_get_contents_checksum (tree));

ostree_mutable_tree_set_contents_checksum (tree, checksum);
g_assert_cmpstr (checksum, ==, ostree_mutable_tree_get_contents_checksum (tree));

g_assert (ostree_mutable_tree_ensure_dir (tree, "subdir", &subdir, &error));
g_assert (ostree_mutable_tree_ensure_dir (tree, "subdir", &subdir, NULL));
g_assert_nonnull (subdir);

ostree_mutable_tree_set_contents_checksum (subdir, subdir_checksum);
Expand Down

0 comments on commit 7453b30

Please sign in to comment.