From 11b1f372c6df886c8eaa806a8032569da11ee261 Mon Sep 17 00:00:00 2001 From: William Manley Date: Fri, 22 Jun 2018 11:37:37 +0100 Subject: [PATCH 1/3] OstreeMutableTree: Document each private member of `OstreeMutableTree` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A prelude to my understanding. Unfortunately `OstreeMutableTree` provides little encapsulation, as each member has setters† so it's difficult to come up with a list of invariants. † `files` and `subdirs` only have getters, but the getters return mutable references to the internals, so we still can't reason about invariants. --- src/libostree/ostree-mutable-tree.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libostree/ostree-mutable-tree.c b/src/libostree/ostree-mutable-tree.c index 5cff5d82bd..f46e36dbe4 100644 --- a/src/libostree/ostree-mutable-tree.c +++ b/src/libostree/ostree-mutable-tree.c @@ -47,10 +47,20 @@ struct OstreeMutableTree { GObject parent_instance; + /* This is the checksum of the Dirtree object that corresponds to the current + * contents of this directory. contents_checksum can be NULL if the SHA was + * never calculated or contents of the mtree has been modified. Even if + * contents_checksum is not NULL it may be out of date. */ char *contents_checksum; + + /* This is the checksum of the DirMeta object that holds the uid, gid, mode + * and xattrs of this directory. This can be NULL. */ char *metadata_checksum; + /* const char* filename -> const char* checksum */ GHashTable *files; + + /* const char* filename -> OstreeMutableTree* subtree */ GHashTable *subdirs; }; From 48f64451c5e381056cb9d220b47eb685be86852d Mon Sep 17 00:00:00 2001 From: William Manley Date: Fri, 22 Jun 2018 12:00:29 +0100 Subject: [PATCH 2/3] OstreeMutableTree: Document ostree_mutable_tree_ensure_dir --- src/libostree/ostree-mutable-tree.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libostree/ostree-mutable-tree.c b/src/libostree/ostree-mutable-tree.c index f46e36dbe4..e5e282d4d0 100644 --- a/src/libostree/ostree-mutable-tree.c +++ b/src/libostree/ostree-mutable-tree.c @@ -186,6 +186,16 @@ ostree_mutable_tree_replace_file (OstreeMutableTree *self, return ret; } +/** + * ostree_mutable_tree_ensure_dir: + * @self: Tree + * @name: Name of subdirectory of self to retrieve/creates + * @out_subdir: (out) (transfer full): the subdirectory + * @error: a #GError + * + * Returns the subdirectory of self with filename @name, creating an empty one + * it if it doesn't exist. + */ gboolean ostree_mutable_tree_ensure_dir (OstreeMutableTree *self, const char *name, From 36f7a6d18267814b4d11cb5a89e2ed7993b3d543 Mon Sep 17 00:00:00 2001 From: William Manley Date: Sat, 23 Jun 2018 13:11:07 +0100 Subject: [PATCH 3/3] Add test for composing trees in different ways In preparation for adding `ostree commit` optimisations. --- tests/basic-test.sh | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/basic-test.sh b/tests/basic-test.sh index e0ed2c3233..a0c2f1f763 100644 --- a/tests/basic-test.sh +++ b/tests/basic-test.sh @@ -435,6 +435,54 @@ $OSTREE checkout test3-combined checkout-test3-combined assert_has_file checkout-test3-combined/file-a assert_has_file checkout-test3-combined/file-b +mkdir -p tree-C/usr/share tree-C/usr/bin tree-C/etc tree-D/etc + +echo exe >tree-C/usr/bin/exe +echo sudoers1 >tree-C/etc/sudoers +echo mtab >tree-C/etc/mtab + +echo sudoers2 >tree-D/etc/sudoers + +$OSTREE commit ${COMMIT_ARGS} -b test3-C1 --tree=dir=tree-C +$OSTREE commit ${COMMIT_ARGS} -b test3-D --tree=dir=tree-D + +echo sudoers2 >tree-C/etc/sudoers +$OSTREE commit ${COMMIT_ARGS} -b test3-C2 --tree=dir=tree-C +echo sudoers1 >tree-C/etc/sudoers + +$OSTREE commit ${COMMIT_ARGS} -b test3-ref-ref --tree=ref=test3-C1 --tree=ref=test3-D +$OSTREE commit ${COMMIT_ARGS} -b test3-dir-ref --tree=dir=tree-C --tree=ref=test3-D +$OSTREE commit ${COMMIT_ARGS} -b test3-ref-dir --tree=ref=test3-C1 --tree=dir=tree-D +$OSTREE commit ${COMMIT_ARGS} -b test3-dir-dir --tree=dir=tree-C --tree=dir=tree-D + +assert_trees_identical() { + $OSTREE diff "$1" "$2" > "diff-$1-$2" + cat "diff-$1-$2" 1>&2 + assert_file_empty "diff-$1-$2" + rm "diff-$1-$2" +} + +for x in ref dir +do + for y in ref dir + do + assert_trees_identical test3-C2 "test3-$x-$y" + done +done + +# Regression test + +mkdir -p tree-E/etc +mkdir -p tree-F/etc/apt/sources.list.d/ +echo contents >tree-F/etc/apt/sources.list.d/universe.list + +$OSTREE commit ${COMMIT_ARGS} -b test3-E --tree=dir=tree-E +$OSTREE commit ${COMMIT_ARGS} -b test3-F --tree=dir=tree-F + +$OSTREE commit ${COMMIT_ARGS} -b test3-F2 --tree=ref=test3-E --tree=ref=test3-F + +assert_trees_identical test3-F test3-F2 + echo "ok commit combined ref trees" # NB: The + is optional, but we need to make sure we support it