[ostree/wip/repo-file: 7/7] repo-libarchive: Apply commit modifiers to libarchive archives as well
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree/wip/repo-file: 7/7] repo-libarchive: Apply commit modifiers to libarchive archives as well
- Date: Sat, 7 Sep 2013 15:15:50 +0000 (UTC)
commit 85392a25fa7c9c5da6b41aa86f8f8cfba9e0376c
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Sat Sep 7 00:42:25 2013 -0400
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.
src/libostree/ostree-repo-commit.c | 34 ++++++++++++++++++----
src/libostree/ostree-repo-libarchive.c | 48 ++++++++++++++++----------------
src/libostree/ostree-repo-private.h | 7 ++++
src/libostree/ostree-repo.h | 2 +-
4 files changed, 59 insertions(+), 32 deletions(-)
---
diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c
index 2b38f23..f491dc8 100644
--- a/src/libostree/ostree-repo-commit.c
+++ b/src/libostree/ostree-repo-commit.c
@@ -1327,17 +1327,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)
{
@@ -1351,6 +1372,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];
@@ -1360,9 +1382,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;
diff --git a/src/libostree/ostree-repo-libarchive.c b/src/libostree/ostree-repo-libarchive.c
index b75d3fa..b7efaac 100644
--- a/src/libostree/ostree-repo-libarchive.c
+++ b/src/libostree/ostree-repo-libarchive.c
@@ -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,10 +75,10 @@ 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);
+ _ostree_repo_commit_modifier_apply (repo, modifier,
+ archive_entry_pathname (entry),
+ info, &modified_info);
- g_object_unref (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))
diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h
index 0060ca4..81c5633 100644
--- a/src/libostree/ostree-repo-private.h
+++ b/src/libostree/ostree-repo-private.h
@@ -109,5 +109,12 @@ _ostree_repo_update_refs (OstreeRepo *self,
GCancellable *cancellable,
GError **error);
+OstreeRepoCommitFilterResult
+_ostree_repo_commit_modifier_apply (OstreeRepo *self,
+ OstreeRepoCommitModifier *modifier,
+ const char *path,
+ GFileInfo *file_info,
+ GFileInfo **out_modified_info);
+
G_END_DECLS
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 2d2f9c0..9cca662 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]