From 7f197a5370bd3d6be33eb42b0a6755963375dbf6 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 13 Sep 2017 16:05:47 +0000 Subject: [PATCH 1/2] lib/commit: add comments to explain dir commit path Add a few comments for each of the central functions used for committing data from a directory. Took me a bit to understand the relationship between those functions. --- src/libostree/ostree-repo-commit.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 4f99f2dc79..28c747c9cc 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -2480,6 +2480,10 @@ write_dfd_iter_to_mtree_internal (OstreeRepo *self, GCancellable *cancellable, GError **error); +/* Given either a dir_enum or a dfd_iter, writes the directory entry to the mtree. For + * subdirs, we go back through either write_dfd_iter_to_mtree_internal (dfd_iter case) or + * write_directory_to_mtree_internal (dir_enum case) which will do the actual dirmeta + + * dirent iteration. */ static gboolean write_directory_content_to_mtree_internal (OstreeRepo *self, OstreeRepoFile *repo_dir, @@ -2632,6 +2636,8 @@ write_directory_content_to_mtree_internal (OstreeRepo *self, return TRUE; } +/* Handles the dirmeta for the given GFile dir and then calls + * write_directory_content_to_mtree_internal() for each directory entry. */ static gboolean write_directory_to_mtree_internal (OstreeRepo *self, GFile *dir, @@ -2729,6 +2735,8 @@ write_directory_to_mtree_internal (OstreeRepo *self, return TRUE; } +/* Handles the dirmeta for the dir described by src_dfd_iter and then calls + * write_directory_content_to_mtree_internal() for each directory entry. */ static gboolean write_dfd_iter_to_mtree_internal (OstreeRepo *self, GLnxDirFdIterator *src_dfd_iter, From d33828e68945eef0f3a0e5b05888ddb8be675187 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 13 Sep 2017 16:17:17 +0000 Subject: [PATCH 2/2] lib/commit: fix using uninitialized var Noticed this while reading the code. The `child` var hasn't been initialized yet at the time we throw this error (and even then, it's only conditionally initialized). To be nice, let's just always calculate the child path and pass that along. Also do some minor style porting to decl near use. --- src/libostree/ostree-repo-commit.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 28c747c9cc..f70d1859bd 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -2496,23 +2496,16 @@ write_directory_content_to_mtree_internal (OstreeRepo *self, GCancellable *cancellable, GError **error) { - g_autoptr(GFile) child = NULL; - g_autoptr(GFileInfo) modified_info = NULL; - g_autoptr(OstreeMutableTree) child_mtree = NULL; - g_autofree char *child_relpath = NULL; - const char *name; - GFileType file_type; - OstreeRepoCommitFilterResult filter_result; - g_assert (dir_enum != NULL || dfd_iter != NULL); - name = g_file_info_get_name (child_info); + const char *name = g_file_info_get_name (child_info); g_ptr_array_add (path, (char*)name); - if (modifier != NULL) - child_relpath = ptrarray_path_join (path); + g_autofree char *child_relpath = ptrarray_path_join (path); - filter_result = _ostree_repo_commit_modifier_apply (self, modifier, child_relpath, child_info, &modified_info); + g_autoptr(GFileInfo) modified_info = NULL; + OstreeRepoCommitFilterResult filter_result = + _ostree_repo_commit_modifier_apply (self, modifier, child_relpath, child_info, &modified_info); if (filter_result != OSTREE_REPO_COMMIT_FILTER_ALLOW) { @@ -2521,7 +2514,7 @@ write_directory_content_to_mtree_internal (OstreeRepo *self, return TRUE; } - file_type = g_file_info_get_file_type (child_info); + GFileType file_type = g_file_info_get_file_type (child_info); switch (file_type) { case G_FILE_TYPE_DIRECTORY: @@ -2529,15 +2522,16 @@ write_directory_content_to_mtree_internal (OstreeRepo *self, case G_FILE_TYPE_REGULAR: break; default: - return glnx_throw (error, "Unsupported file type: '%s'", - gs_file_get_path_cached (child)); + return glnx_throw (error, "Unsupported file type for file: '%s'", child_relpath); } + g_autoptr(GFile) child = NULL; if (dir_enum != NULL) child = g_file_enumerator_get_child (dir_enum, child_info); if (file_type == G_FILE_TYPE_DIRECTORY) { + g_autoptr(OstreeMutableTree) child_mtree = NULL; if (!ostree_mutable_tree_ensure_dir (mtree, name, &child_mtree, error)) return FALSE;