commit: Split out file processing into helper function
There should be no logic change here, just reducing indentation.
This commit is contained in:
parent
e5b147c643
commit
a35c4a564d
|
|
@ -1864,107 +1864,27 @@ write_directory_to_mtree_internal (OstreeRepo *self,
|
|||
OstreeRepoCommitModifier *modifier,
|
||||
GPtrArray *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
static gboolean
|
||||
write_directory_content_to_mtree_internal (OstreeRepo *self,
|
||||
OstreeRepoFile *repo_dir,
|
||||
GFileEnumerator *dir_enum,
|
||||
GFileInfo *child_info,
|
||||
OstreeMutableTree *mtree,
|
||||
OstreeRepoCommitModifier *modifier,
|
||||
GPtrArray *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
OstreeRepoCommitFilterResult filter_result;
|
||||
OstreeRepoFile *repo_dir = NULL;
|
||||
gs_unref_object GFileEnumerator *dir_enum = NULL;
|
||||
gs_unref_object GFileInfo *child_info = NULL;
|
||||
|
||||
g_debug ("Examining: %s", gs_file_get_path_cached (dir));
|
||||
|
||||
if (modifier && modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES)
|
||||
{
|
||||
self->generate_sizes = TRUE;
|
||||
}
|
||||
|
||||
/* If the directory is already in the repository, we can try to
|
||||
* reuse checksums to skip checksumming. */
|
||||
if (OSTREE_IS_REPO_FILE (dir) && modifier == NULL)
|
||||
repo_dir = (OstreeRepoFile *) dir;
|
||||
|
||||
if (repo_dir)
|
||||
{
|
||||
if (!ostree_repo_file_ensure_resolved (repo_dir, error))
|
||||
goto out;
|
||||
|
||||
ostree_mutable_tree_set_metadata_checksum (mtree, ostree_repo_file_tree_get_metadata_checksum (repo_dir));
|
||||
|
||||
/* If the mtree was empty beforehand, the checksums on the mtree can simply
|
||||
* become the checksums on the tree in the repo. Super simple. */
|
||||
if (g_hash_table_size (ostree_mutable_tree_get_files (mtree)) == 0 &&
|
||||
g_hash_table_size (ostree_mutable_tree_get_subdirs (mtree)) == 0)
|
||||
{
|
||||
ostree_mutable_tree_set_contents_checksum (mtree, ostree_repo_file_tree_get_contents_checksum (repo_dir));
|
||||
ret = TRUE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
filter_result = OSTREE_REPO_COMMIT_FILTER_ALLOW;
|
||||
}
|
||||
else
|
||||
{
|
||||
gs_unref_object GFileInfo *modified_info = NULL;
|
||||
gs_unref_variant GVariant *xattrs = NULL;
|
||||
gs_free guchar *child_file_csum = NULL;
|
||||
gs_free char *tmp_checksum = NULL;
|
||||
gs_free char *relpath = NULL;
|
||||
|
||||
child_info = g_file_query_info (dir, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable, error);
|
||||
if (!child_info)
|
||||
goto out;
|
||||
|
||||
if (modifier != NULL)
|
||||
relpath = ptrarray_path_join (path);
|
||||
|
||||
filter_result = apply_commit_filter (self, modifier, relpath, child_info, &modified_info);
|
||||
|
||||
if (filter_result == OSTREE_REPO_COMMIT_FILTER_ALLOW)
|
||||
{
|
||||
g_debug ("Adding: %s", gs_file_get_path_cached (dir));
|
||||
if (!get_modified_xattrs (self, modifier, relpath, child_info, dir,
|
||||
&xattrs,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (!_ostree_repo_write_directory_meta (self, modified_info, xattrs, &child_file_csum,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
|
||||
g_free (tmp_checksum);
|
||||
tmp_checksum = ostree_checksum_from_bytes (child_file_csum);
|
||||
ostree_mutable_tree_set_metadata_checksum (mtree, tmp_checksum);
|
||||
}
|
||||
|
||||
g_clear_object (&child_info);
|
||||
}
|
||||
|
||||
if (filter_result == OSTREE_REPO_COMMIT_FILTER_ALLOW)
|
||||
{
|
||||
dir_enum = g_file_enumerate_children ((GFile*)dir, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable,
|
||||
error);
|
||||
if (!dir_enum)
|
||||
goto out;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
GFileInfo *child_info;
|
||||
gs_unref_object GFile *child = NULL;
|
||||
gs_unref_object GFileInfo *modified_info = NULL;
|
||||
gs_unref_object OstreeMutableTree *child_mtree = NULL;
|
||||
gs_free char *child_relpath = NULL;
|
||||
const char *name;
|
||||
|
||||
if (!gs_file_enumerator_iterate (dir_enum, &child_info, NULL,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
if (child_info == NULL)
|
||||
break;
|
||||
GFileType file_type;
|
||||
OstreeRepoCommitFilterResult filter_result;
|
||||
|
||||
name = g_file_info_get_name (child_info);
|
||||
g_ptr_array_add (path, (char*)name);
|
||||
|
|
@ -1974,11 +1894,14 @@ write_directory_to_mtree_internal (OstreeRepo *self,
|
|||
|
||||
filter_result = apply_commit_filter (self, modifier, child_relpath, child_info, &modified_info);
|
||||
|
||||
if (filter_result == OSTREE_REPO_COMMIT_FILTER_ALLOW)
|
||||
if (filter_result != OSTREE_REPO_COMMIT_FILTER_ALLOW)
|
||||
{
|
||||
GFileType file_type;
|
||||
g_ptr_array_remove_index (path, path->len - 1);
|
||||
ret = TRUE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
child = g_file_get_child (dir, name);
|
||||
child = g_file_enumerator_get_child (dir_enum, child_info);
|
||||
|
||||
file_type = g_file_info_get_file_type (child_info);
|
||||
switch (file_type)
|
||||
|
|
@ -2064,7 +1987,122 @@ write_directory_to_mtree_internal (OstreeRepo *self,
|
|||
}
|
||||
|
||||
g_ptr_array_remove_index (path, path->len - 1);
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
write_directory_to_mtree_internal (OstreeRepo *self,
|
||||
GFile *dir,
|
||||
OstreeMutableTree *mtree,
|
||||
OstreeRepoCommitModifier *modifier,
|
||||
GPtrArray *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
OstreeRepoCommitFilterResult filter_result;
|
||||
OstreeRepoFile *repo_dir = NULL;
|
||||
gs_unref_object GFileEnumerator *dir_enum = NULL;
|
||||
gs_unref_object GFileInfo *child_info = NULL;
|
||||
|
||||
g_debug ("Examining: %s", gs_file_get_path_cached (dir));
|
||||
|
||||
if (modifier && modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES)
|
||||
{
|
||||
self->generate_sizes = TRUE;
|
||||
}
|
||||
|
||||
/* If the directory is already in the repository, we can try to
|
||||
* reuse checksums to skip checksumming. */
|
||||
if (OSTREE_IS_REPO_FILE (dir) && modifier == NULL)
|
||||
repo_dir = (OstreeRepoFile *) dir;
|
||||
|
||||
if (repo_dir)
|
||||
{
|
||||
if (!ostree_repo_file_ensure_resolved (repo_dir, error))
|
||||
goto out;
|
||||
|
||||
ostree_mutable_tree_set_metadata_checksum (mtree, ostree_repo_file_tree_get_metadata_checksum (repo_dir));
|
||||
|
||||
/* If the mtree was empty beforehand, the checksums on the mtree can simply
|
||||
* become the checksums on the tree in the repo. Super simple. */
|
||||
if (g_hash_table_size (ostree_mutable_tree_get_files (mtree)) == 0 &&
|
||||
g_hash_table_size (ostree_mutable_tree_get_subdirs (mtree)) == 0)
|
||||
{
|
||||
ostree_mutable_tree_set_contents_checksum (mtree, ostree_repo_file_tree_get_contents_checksum (repo_dir));
|
||||
ret = TRUE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
filter_result = OSTREE_REPO_COMMIT_FILTER_ALLOW;
|
||||
}
|
||||
else
|
||||
{
|
||||
gs_unref_object GFileInfo *modified_info = NULL;
|
||||
gs_unref_variant GVariant *xattrs = NULL;
|
||||
gs_free guchar *child_file_csum = NULL;
|
||||
gs_free char *tmp_checksum = NULL;
|
||||
gs_free char *relpath = NULL;
|
||||
|
||||
child_info = g_file_query_info (dir, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable, error);
|
||||
if (!child_info)
|
||||
goto out;
|
||||
|
||||
if (modifier != NULL)
|
||||
relpath = ptrarray_path_join (path);
|
||||
|
||||
filter_result = apply_commit_filter (self, modifier, relpath, child_info, &modified_info);
|
||||
|
||||
if (filter_result == OSTREE_REPO_COMMIT_FILTER_ALLOW)
|
||||
{
|
||||
g_debug ("Adding: %s", gs_file_get_path_cached (dir));
|
||||
if (!get_modified_xattrs (self, modifier, relpath, child_info, dir,
|
||||
&xattrs,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (!_ostree_repo_write_directory_meta (self, modified_info, xattrs, &child_file_csum,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
|
||||
g_free (tmp_checksum);
|
||||
tmp_checksum = ostree_checksum_from_bytes (child_file_csum);
|
||||
ostree_mutable_tree_set_metadata_checksum (mtree, tmp_checksum);
|
||||
}
|
||||
|
||||
g_clear_object (&child_info);
|
||||
}
|
||||
|
||||
if (filter_result == OSTREE_REPO_COMMIT_FILTER_ALLOW)
|
||||
{
|
||||
gs_unref_object GFileEnumerator *dir_enum = NULL;
|
||||
|
||||
dir_enum = g_file_enumerate_children ((GFile*)dir, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable,
|
||||
error);
|
||||
if (!dir_enum)
|
||||
goto out;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
GFileInfo *child_info;
|
||||
|
||||
if (!gs_file_enumerator_iterate (dir_enum, &child_info, NULL,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
if (child_info == NULL)
|
||||
break;
|
||||
|
||||
if (!write_directory_content_to_mtree_internal (self, repo_dir, dir_enum, child_info,
|
||||
mtree, modifier, path,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue