[ostree] repo: Expose dfd-relative mtree writes as public API



commit 21fbc16bc35869b547ec4f2bdbef59af9ce0ccc9
Author: Colin Walters <walters verbum org>
Date:   Mon Jan 4 17:51:56 2016 -0500

    repo: Expose dfd-relative mtree writes as public API
    
    For use in rpm-ostree.  We already had all of the internals for this.

 doc/ostree-sections.txt            |    1 +
 src/libostree/ostree-repo-commit.c |   70 +++++++++++++++++++++++++++---------
 src/libostree/ostree-repo.h        |    8 ++++
 3 files changed, 62 insertions(+), 17 deletions(-)
---
diff --git a/doc/ostree-sections.txt b/doc/ostree-sections.txt
index 5e9dfb9..131ee1b 100644
--- a/doc/ostree-sections.txt
+++ b/doc/ostree-sections.txt
@@ -279,6 +279,7 @@ ostree_repo_commit_modifier_set_sepolicy
 ostree_repo_commit_modifier_ref
 ostree_repo_commit_modifier_unref
 ostree_repo_write_directory_to_mtree
+ostree_repo_write_dfd_to_mtree
 ostree_repo_write_archive_to_mtree
 ostree_repo_write_mtree
 ostree_repo_write_commit
diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c
index d861e62..5faa25e 100644
--- a/src/libostree/ostree-repo-commit.c
+++ b/src/libostree/ostree-repo-commit.c
@@ -2823,28 +2823,21 @@ ostree_repo_write_directory_to_mtree (OstreeRepo                *self,
                                       GError                   **error)
 {
   gboolean ret = FALSE;
-  GPtrArray *path = NULL;
+  g_autoptr(GPtrArray) path = NULL;
 
-  if (modifier && modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES)
-    {
-      self->generate_sizes = TRUE;
-    }
-
-  path = g_ptr_array_new ();
+  /* Short cut local files */
   if (g_file_is_native (dir))
     {
-      gs_dirfd_iterator_cleanup GSDirFdIterator dfd_iter = { 0, };
-
-      if (!gs_dirfd_iterator_init_at (AT_FDCWD, gs_file_get_path_cached (dir), FALSE,
-                                      &dfd_iter, error))
-        goto out;
-
-      if (!write_dfd_iter_to_mtree_internal (self, &dfd_iter, mtree, modifier, path,
-                                             cancellable, error))
+      if (!ostree_repo_write_dfd_to_mtree (self, AT_FDCWD, gs_file_get_path_cached (dir),
+                                           mtree, modifier, cancellable, error))
         goto out;
     }
   else
     {
+      if (modifier && modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES)
+        self->generate_sizes = TRUE;
+      
+      path = g_ptr_array_new ();
       if (!write_directory_to_mtree_internal (self, dir, mtree, modifier, path,
                                               cancellable, error))
         goto out;
@@ -2852,8 +2845,51 @@ ostree_repo_write_directory_to_mtree (OstreeRepo                *self,
 
   ret = TRUE;
  out:
-  if (path)
-    g_ptr_array_free (path, TRUE);
+  return ret;
+}
+
+/**
+ * ostree_repo_write_dfd_to_mtree:
+ * @self: Repo
+ * @dfd: Directory file descriptor
+ * @path: Path
+ * @mtree: Overlay directory contents into this tree
+ * @modifier: (allow-none): Optional modifier
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Store as objects all contents of the directory referred to by @dfd
+ * and @path all children into the repository @self, overlaying the
+ * resulting filesystem hierarchy into @mtree.
+ */
+gboolean
+ostree_repo_write_dfd_to_mtree (OstreeRepo                *self,
+                                int                        dfd,
+                                const char                *path,
+                                OstreeMutableTree         *mtree,
+                                OstreeRepoCommitModifier  *modifier,
+                                GCancellable              *cancellable,
+                                GError                   **error)
+{
+  gboolean ret = FALSE;
+  g_autoptr(GPtrArray) pathbuilder = NULL;
+  gs_dirfd_iterator_cleanup GSDirFdIterator dfd_iter = { 0, };
+
+  if (modifier && modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES)
+    self->generate_sizes = TRUE;
+
+  pathbuilder = g_ptr_array_new ();
+
+  if (!gs_dirfd_iterator_init_at (dfd, path, FALSE,
+                                  &dfd_iter, error))
+    goto out;
+
+  if (!write_dfd_iter_to_mtree_internal (self, &dfd_iter, mtree, modifier, pathbuilder,
+                                         cancellable, error))
+    goto out;
+
+  ret = TRUE;
+ out:
   return ret;
 }
 
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 1680de8..5f1b497 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -428,6 +428,14 @@ gboolean      ostree_repo_write_directory_to_mtree (OstreeRepo                 *
                                                     GCancellable               *cancellable,
                                                     GError                    **error);
 
+gboolean      ostree_repo_write_dfd_to_mtree (OstreeRepo                 *self,
+                                              int                         dfd,
+                                              const char                 *path,
+                                              OstreeMutableTree          *mtree,
+                                              OstreeRepoCommitModifier   *modifier,
+                                              GCancellable               *cancellable,
+                                              GError                    **error);
+
 gboolean      ostree_repo_write_archive_to_mtree (OstreeRepo                   *self,
                                                   GFile                        *archive,
                                                   OstreeMutableTree            *mtree,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]