repo-libarchive: Apply commit modifiers to libarchive archives as well

And document the libarchive methods as well, so we can pass a NULL
commit modifier.

https://bugzilla.gnome.org/show_bug.cgi?id=707727
This commit is contained in:
Jasper St. Pierre 2013-09-07 00:42:25 -04:00
parent c7f9fc9c63
commit 6b4ef97c18
4 changed files with 59 additions and 32 deletions

View File

@ -1395,17 +1395,38 @@ struct OstreeRepoCommitModifier {
GDestroyNotify destroy_notify;
};
static OstreeRepoCommitFilterResult
apply_commit_filter (OstreeRepo *self,
OstreeRepoCommitFilterResult
_ostree_repo_commit_modifier_apply (OstreeRepo *self,
OstreeRepoCommitModifier *modifier,
const char *path,
GFileInfo *file_info,
GFileInfo **out_modified_info)
{
OstreeRepoCommitFilterResult result;
GFileInfo *modified_info;
if (modifier == NULL || modifier->filter == NULL)
{
*out_modified_info = g_object_ref (file_info);
return OSTREE_REPO_COMMIT_FILTER_ALLOW;
}
modified_info = g_file_info_dup (file_info);
result = modifier->filter (self, path, modified_info, modifier->user_data);
*out_modified_info = modified_info;
return result;
}
static gboolean
apply_commit_filter (OstreeRepo *self,
OstreeRepoCommitModifier *modifier,
GPtrArray *path,
GFileInfo *file_info,
GFileInfo **out_modified_info)
{
GString *path_buf;
guint i;
OstreeRepoCommitFilterResult result;
GFileInfo *modified_info;
if (modifier == NULL || modifier->filter == NULL)
{
@ -1419,6 +1440,7 @@ apply_commit_filter (OstreeRepo *self,
g_string_append_c (path_buf, '/');
else
{
guint i;
for (i = 0; i < path->len; i++)
{
const char *elt = path->pdata[i];
@ -1428,9 +1450,7 @@ apply_commit_filter (OstreeRepo *self,
}
}
modified_info = g_file_info_dup (file_info);
result = modifier->filter (self, path_buf->str, modified_info, modifier->user_data);
*out_modified_info = modified_info;
result = _ostree_repo_commit_modifier_apply (self, modifier, path_buf->str, file_info, out_modified_info);
g_string_free (path_buf, TRUE);
return result;

View File

@ -35,20 +35,6 @@
#ifdef HAVE_LIBARCHIVE
static GFileInfo *
create_modified_file_info (GFileInfo *info,
OstreeRepoCommitModifier *modifier)
{
GFileInfo *ret;
if (!modifier)
return (GFileInfo*)g_object_ref (info);
ret = g_file_info_dup (info);
return ret;
}
static void
propagate_libarchive_error (GError **error,
struct archive *a)
@ -58,10 +44,11 @@ propagate_libarchive_error (GError **error,
}
static GFileInfo *
file_info_from_archive_entry_and_modifier (struct archive_entry *entry,
file_info_from_archive_entry_and_modifier (OstreeRepo *repo,
struct archive_entry *entry,
OstreeRepoCommitModifier *modifier)
{
GFileInfo *info = g_file_info_new ();
gs_unref_object GFileInfo *info = g_file_info_new ();
GFileInfo *modified_info = NULL;
const struct stat *st;
guint32 file_type;
@ -88,9 +75,9 @@ file_info_from_archive_entry_and_modifier (struct archive_entry *entry,
g_file_info_set_attribute_uint32 (info, "unix::rdev", st->st_rdev);
}
modified_info = create_modified_file_info (info, modifier);
g_object_unref (info);
_ostree_repo_commit_modifier_apply (repo, modifier,
archive_entry_pathname (entry),
info, &modified_info);
return modified_info;
}
@ -230,7 +217,7 @@ write_libarchive_entry_to_mtree (OstreeRepo *self,
}
else
{
file_info = file_info_from_archive_entry_and_modifier (entry, modifier);
file_info = file_info_from_archive_entry_and_modifier (self, entry, modifier);
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_UNKNOWN)
{
@ -287,10 +274,23 @@ write_libarchive_entry_to_mtree (OstreeRepo *self,
}
#endif
/**
* ostree_repo_write_archive_to_mtree:
* @self: An #OstreeRepo
* @archive: A path to an archive file
* @mtree: The #OstreeMutableTree to write to
* @modifier: (allow-none): Optional commit modifier
* @autocreate_parents: Autocreate parent directories
* @cancellable: Cancellable
* @error: Error
*
* Import an archive file @archive into the repository, and write its
* file structure to @mtree.
*/
gboolean
ostree_repo_write_archive_to_mtree (OstreeRepo *self,
GFile *archive_f,
OstreeMutableTree *root,
GFile *archive,
OstreeMutableTree *mtree,
OstreeRepoCommitModifier *modifier,
gboolean autocreate_parents,
GCancellable *cancellable,
@ -311,7 +311,7 @@ ostree_repo_write_archive_to_mtree (OstreeRepo *self,
archive_read_support_compression_all (a);
#endif
archive_read_support_format_all (a);
if (archive_read_open_filename (a, gs_file_get_path_cached (archive_f), 8192) != ARCHIVE_OK)
if (archive_read_open_filename (a, gs_file_get_path_cached (archive), 8192) != ARCHIVE_OK)
{
propagate_libarchive_error (error, a);
goto out;
@ -340,7 +340,7 @@ ostree_repo_write_archive_to_mtree (OstreeRepo *self,
goto out;
}
if (!write_libarchive_entry_to_mtree (self, root, a,
if (!write_libarchive_entry_to_mtree (self, mtree, a,
entry, modifier,
autocreate_parents ? tmp_csum : NULL,
cancellable, error))

View File

@ -121,5 +121,12 @@ _ostree_repo_file_new_root (OstreeRepo *repo,
const char *contents_checksum,
const char *metadata_checksum);
OstreeRepoCommitFilterResult
_ostree_repo_commit_modifier_apply (OstreeRepo *self,
OstreeRepoCommitModifier *modifier,
const char *path,
GFileInfo *file_info,
GFileInfo **out_modified_info);
G_END_DECLS

View File

@ -302,7 +302,7 @@ gboolean ostree_repo_write_directory_to_mtree (OstreeRepo *
gboolean ostree_repo_write_archive_to_mtree (OstreeRepo *self,
GFile *archive,
OstreeMutableTree *tree,
OstreeMutableTree *mtree,
OstreeRepoCommitModifier *modifier,
gboolean autocreate_parents,
GCancellable *cancellable,