[ostree] core: Add an API to parse a content file using dirfd relative lookup



commit a7300a828db26749e79d2e290eb561698d84655a
Author: Colin Walters <walters verbum org>
Date:   Wed Jan 14 22:03:02 2015 -0500

    core: Add an API to parse a content file using dirfd relative lookup
    
    This will be used for a later change to use openat() for the fetching
    code.  Note that we drop the code to use mmap() - it was an attempt to
    avoid keeping a fd open, but we do correctly close anyways.

 src/libostree/ostree-core.c |   88 ++++++++++++++++++++++++------------------
 src/libostree/ostree-core.h |   10 +++++
 2 files changed, 60 insertions(+), 38 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index 2d70e22..08e0ea2 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -574,9 +574,10 @@ ostree_content_stream_parse (gboolean                compressed,
 }
 
 /**
- * ostree_content_file_parse:
+ * ostree_content_file_parse_at:
  * @compressed: Whether or not the stream is zlib-compressed
- * @content_path: Path to file containing content
+ * @parent_dfd: Directory file descriptor
+ * @path: Subpath
  * @trusted: If %TRUE, assume the content has been validated
  * @out_input: (out): The raw file content stream
  * @out_file_info: (out): Normal metadata 
@@ -588,51 +589,31 @@ ostree_content_stream_parse (gboolean                compressed,
  * converts an object content stream back into components.
  */
 gboolean
-ostree_content_file_parse (gboolean                compressed,
-                           GFile                  *content_path,
-                           gboolean                trusted,
-                           GInputStream          **out_input,
-                           GFileInfo             **out_file_info,
-                           GVariant              **out_xattrs,
-                           GCancellable           *cancellable,
-                           GError                **error)
+ostree_content_file_parse_at (gboolean                compressed,
+                              int                     parent_dfd,
+                              const char             *path,
+                              gboolean                trusted,
+                              GInputStream          **out_input,
+                              GFileInfo             **out_file_info,
+                              GVariant              **out_xattrs,
+                              GCancellable           *cancellable,
+                              GError                **error)
 {
   gboolean ret = FALSE;
-  guint64 length;
   struct stat stbuf;
   gs_unref_object GInputStream *file_input = NULL;
   gs_unref_object GInputStream *ret_input = NULL;
   gs_unref_object GFileInfo *ret_file_info = NULL;
   gs_unref_variant GVariant *ret_xattrs = NULL;
 
-  if (out_input)
-    {
-      file_input = (GInputStream*)gs_file_read_noatime (content_path, cancellable, error);
-      if (!file_input)
-        goto out;
+  if (!ot_openat_read_stream (parent_dfd, path, TRUE, &file_input,
+                              cancellable, error))
+    goto out;
       
-      if (!gs_stream_fstat ((GFileDescriptorBased*)file_input, &stbuf, cancellable, error))
-        goto out;
-
-      length = stbuf.st_size;
-    }
-  else
-    {
-      GMappedFile *mmaped;
-      GBytes *bytes;
-
-      mmaped = gs_file_map_noatime (content_path, cancellable, error);
-      if (!mmaped)
-        goto out;
-      bytes = g_mapped_file_get_bytes (mmaped);
-      g_mapped_file_unref (mmaped);
-      mmaped = NULL;
-      file_input = g_memory_input_stream_new_from_bytes (bytes);
-      length = g_bytes_get_size (bytes);
-      g_bytes_unref (bytes);
-    }
-
-  if (!ostree_content_stream_parse (compressed, file_input, length, trusted,
+  if (!gs_stream_fstat ((GFileDescriptorBased*)file_input, &stbuf, cancellable, error))
+    goto out;
+  
+  if (!ostree_content_stream_parse (compressed, file_input, stbuf.st_size, trusted,
                                     out_input ? &ret_input : NULL,
                                     &ret_file_info, &ret_xattrs,
                                     cancellable, error))
@@ -647,6 +628,37 @@ ostree_content_file_parse (gboolean                compressed,
 }
 
 /**
+ * ostree_content_file_parse:
+ * @compressed: Whether or not the stream is zlib-compressed
+ * @content_path: Path to file containing content
+ * @trusted: If %TRUE, assume the content has been validated
+ * @out_input: (out): The raw file content stream
+ * @out_file_info: (out): Normal metadata 
+ * @out_xattrs: (out): Extended attributes
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * A thin wrapper for ostree_content_stream_parse(); this function
+ * converts an object content stream back into components.
+ */
+gboolean
+ostree_content_file_parse (gboolean                compressed,
+                           GFile                  *content_path,
+                           gboolean                trusted,
+                           GInputStream          **out_input,
+                           GFileInfo             **out_file_info,
+                           GVariant              **out_xattrs,
+                           GCancellable           *cancellable,
+                           GError                **error)
+{
+  return ostree_content_file_parse_at (compressed, AT_FDCWD,
+                                       gs_file_get_path_cached (content_path),
+                                       trusted,
+                                       out_input, out_file_info, out_xattrs,
+                                       cancellable, error);
+}
+
+/**
  * ostree_checksum_file_from_input:
  * @file_info: File information
  * @xattrs: (allow-none): Optional extended attributes
diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h
index c5c940e..b8b0f58 100644
--- a/src/libostree/ostree-core.h
+++ b/src/libostree/ostree-core.h
@@ -229,6 +229,16 @@ gboolean ostree_content_file_parse (gboolean                compressed,
                                     GCancellable           *cancellable,
                                     GError                **error);
 
+gboolean ostree_content_file_parse_at (gboolean                compressed,
+                                       int                     parent_dfd,
+                                       const char             *path,
+                                       gboolean                trusted,
+                                       GInputStream          **out_input,
+                                       GFileInfo             **out_file_info,
+                                       GVariant              **out_xattrs,
+                                       GCancellable           *cancellable,
+                                       GError                **error);
+
 gboolean ostree_raw_file_to_content_stream (GInputStream       *input,
                                             GFileInfo          *file_info,
                                             GVariant           *xattrs,


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